Arrow functions are anonymous function expressions. They don’t show up in stack traces.
function
, return
and some {..}
this
keyword. The arrow function doesn’t have it’s own this
so we automatically get a lexical this
(bind to the outer context). Skipping .bind(this)
console.log
when using the concise arrow function syntax. You have to change the syntax first in order to console.log()
. 1=> 3 // or (var foo = => 3) headless syntax proposal
2() => 3 // no params
3(x) => 3
4x => 3 // no parens, placeholder for params looks an awful lot like funcion invocation
5(x,y) => 3 // parens
6(...x) => 3 // parens
7
8x => { try { 3 } catch(e) {} }
9x => { return 3 }
10x => ({ y: x}) // gotta wrap parens around the object body in order to return an object
1var foo = x => 3
2foo.name // "foo" the interpretor made a guess (inferred) that you want to reference the function with the name foo, based upon where the function expression got saved.
Name inferencing doesn’t work when you pass an arrow function as a param to another function. They’re gonna stay syntactically anonymous.
1foo( x => 3)
{}
it’s an implied return. if you use {}
you gotta use the return keyword inside as well. Or have curly brackets wrapped in parens ({ .. })