7.1 says function expressions are always unnamed, but this changed in ES6
See original GitHub issue7.1 contains this statement:
Function declarations are named, so they’re easier to identify in call stacks.
Anonymous function expressions assigned to a binding are also named, per ES6 semantics (1.e.iii). That is, the “bad” example const foo = function () { };
is the same as const foo = function foo() { };
, which is equivalent to the “good” example function foo() { }
in that respect.
Should the statement be qualified that it’s only a distinction for ES5 and below ?
Issue Analytics
- State:
- Created 8 years ago
- Reactions:1
- Comments:39 (3 by maintainers)
Top Results From Across the Web
Can someone please explain why the AirBnb Style Guide ...
I read this (https://github.com/airbnb/javascript#functions) but I really don't understand it. I think I understand the first sentence.
Read more >The names of functions in ES6 - 2ality
Function names are always assigned during creation and never changed later on. That is, JavaScript engines detect the previously mentioned ...
Read more >7. Symbols - Exploring JS
In ES6, you can use symbols and be sure that they are always unique: const COLOR_RED = Symbol ( 'Red' ); const COLOR_ORANGE...
Read more >ECMAScript 2015 Language Specification – ECMA-262 6th ...
A.1 Lexical Grammar; A.2 Expressions; A.3 Statements; A.4 Functions and ... for numeric output and minor changes in anticipation future language growth.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@amberleyromo indeed, they should be distinct. This is to improve readability and greppability - it lets you use a short variable name, but a long, verbose, unique function name; also, when self-referencing the function, it makes it very clear that you’re referring to the lexical name binding, not the containing variable.
@tandav In your last example, the first function doesn’t have a
.name
- which means in debugging, it’s likely to show up as an anonymous function. In the latter example, it will show up with the namesum
- and when you grep for it, all the uses in the file will usemy_sum
, so the actual function will be easier to locate.