Can someone explain this interesting snippet?
const h1 = () => makeElement(`h1`); const h1 = () => makeElement(`h1`); var h1 = function() {
return makeElement(`h1`);
}
Edited to reflect the valid point brought up in the commentsAlso, no "arguments" (there are ...rest parameters that allow for variadic functions).
I thought the arrows were now binding to surrounding context? (e.g. https://babeljs.io/blog/2015/06/07/react-on-es6-plus)
makeElement(`h1`)
everywhereafter this declaration you can write
h1()
insteadjust a shortcut function
const h1 = () =>
Is this new syntax declaring a function named h1 that returns a function or what? I don't understand what the empty pair of parentheses means. const h1 = function() {
return makeElement('h1');
}
Arrow functions without arguments need empty paranthesis.They also have an implicit return if you don't use {}
So it's not just a syntactic shorthand but there's also a semantic difference.