question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

7.1 says function expressions are always unnamed, but this changed in ES6

See original GitHub issue

7.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:closed
  • Created 8 years ago
  • Reactions:1
  • Comments:39 (3 by maintainers)

github_iconTop GitHub Comments

56reactions
ljharbcommented, Mar 22, 2017

@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.

33reactions
ljharbcommented, Feb 26, 2017

@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 name sum - and when you grep for it, all the uses in the file will use my_sum, so the actual function will be easier to locate.

Read more comments on GitHub >

github_iconTop 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 >
JavaScript Tutorial: The Basics
Basic JavaScript Tutorial for the beginners.
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 >

github_iconTop Related Medium Post

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found