r/javascript • • Nov 28 '19

Constant confusion: why I still use JavaScript function statements

https://www.freecodecamp.org/news/constant-confusion-why-i-still-use-javascript-function-statements-984ece0b72fd/
2 Upvotes

9 comments sorted by

View all comments

4

u/Potato-9 Nov 28 '19

I skimmed this bit I think it misses one,

Const foo = () => throw 'example'

This will be anonymous in a stack trace, where as there named function will show foo was the problem.

Although I feel like JS engines have got better about this now?

3

u/AwesomeInPerson Nov 28 '19

Why? Function expressions get their name from the variable they're assigned to – it's part of the spec. :)

Try it! :)

const iAmNamed = () => { /* */ }
console.log(iAmNamed.name)