3

enter image description here

I can't understand well about the last ways of arrow functions have:

No duplicate named arguments- arrow functions cannot have duplicate named arguments in strict or nonstrict mode, as opposed to nonarrow functions that cannot have duplicate named arguments only in strict mode.

The above paragraph was picked from Book "Understanding ECMAScript 6" wrote by Nicholas C. Zakas in 'Function' chapter.

According to description above, I know that arrow function has not arguments like other function.

I can understand well the sentence before half, but the other half start by "as opposed to...".

What's that mean "nonarrow functions that cannot have duplicate named arguments only in strict mode."

In fact, functions in strict mode also have arguments. I have no idea what the author mean.

dylan
  • 314
  • 1
  • 2
  • 13
  • I actually got confused by 'arguments' and 'named arguments'. I should read more carefully to avoid such misunderstanding. – dylan Jun 28 '16 at 10:04
  • This last bullet point is confusing indeed. You shouldn't use duplicate named parameters anyway. Furthermore, instead of `argument` I would prefer the term `parameter` in this context. –  Jun 28 '16 at 10:12
  • This really should read [*named parameter* instead of *named argument*](http://stackoverflow.com/q/156767/1048572). – Bergi Jun 28 '16 at 10:32

1 Answers1

4

It means that the following is valid JavaScript:

function bar(foo, foo){}

It is not, however, when using strict mode:

'use strict';
function bar(foo, foo){}
// SyntaxError: duplicate formal argument foo

With arrow functions, duplicate named arguments are always, regardless of strict or non-strict mode, invalid.

(foo, foo) => {}
// SyntaxError: duplicate argument names not allowed in this context

According to description above, I know that arrow function has not arguments like other function.

Not sure whether you understood this correctly. Arrow functions can have parameters, it just does not have arguments.

str
  • 42,689
  • 17
  • 109
  • 127
  • Yeah, I know what you mean. I got confused by 'arguments' and 'named arguments' which actually mean parameters. – dylan Jun 28 '16 at 10:06