Naming functions with 'var' or 'let' is possible in JavaScript because functions are first-class in JS unlike some common languages that don't have a functional paradigm (say Java). I think the function foo() {} syntax is mostly to make programmers coming from languages like Java feel comfortable but it does get confusing to have multiple syntax/semantics for declaring functions.
The fat arrow '=>' in ES6 adds yet another way. Personally I think the added complexity in ES6/7 mostly just add bloat and syntactic sugar rather than necessary fixes.
I wonder if it wouldn't have been better to just declare "javascript 2", and write a compiler from "javascript 1/legacy" to "javascript 2" in "javasript 2" -- and suggest browsers/implementers used that.
I mean, do we really need both let and var; function * , function and => (I suppose having to mark a function as re-entrant at least one can understand, though)?
In the presentation, it's not clear (granted without commentary) why one would ever, for new code, write:
// Interpolate expressions into a template string
var name = "Bob",
time = "today";
console.log(`Hello ${name}, how are you ${time}?`);
function dedent(strings, ...values) {
let result = '';
for (let i = 0; i < strings.length; i++) {
result += strings[i].replace(/\n\s+/g, '\n') +
values[i];
}
return result;
}
console.log(dedent `Hello ${name},
How are you ${time}?`);
And not:
let name = "Bob",
time = "today";
console.log(`Hello ${name}, how are you ${time}?`);
let dedent = (strings, ...values) => { // is this valid?
let result = '';
for (let i = 0; i < strings.length; i++) {
result += strings[i].replace(/\n\s+/g, '\n') +
values[i];
}
return result;
}
console.log(dedent `Hello ${name},
How are you ${time}?`);
I understand backwards comparability, but for at least Firefox, let won't work without marking the code in question as v1.7 anyway. It might as well have been Self, Ruby or R6RS.
While having as compact syntax as Smalltalk or Lisp might be going a bit far in the other direction -- I do wish they'd taken the time to simplify the language.