var increment = [1, 2, 3, 4, 5].map( function(num){ return num + 1 } )
The two big syntactic wins of modern JS are let/const over the filth that was var and the convenience of arrow functions over anonymous function literals. var increment = [1, 2, 3, 4, 5].map( function(num){ return num + 1 } )
The two big syntactic wins of modern JS are let/const over the filth that was var and the convenience of arrow functions over anonymous function literals. var increment = function() {
return [1,2,3,4,5].map(function(num) {
return num + 1;
});
};
Moreover, modern JS is not merely convenient syntactic sugar over old JS. Let/const have different scopes, arrow functions have no bindable context.You also now have classes, proxies, async/await, generators, destructuring, default/rest/spread parameters, ...
Add typing via jsdocs or TypeScript and - like the parent comment said - "it's really nice".
Often people mistake JS for a mere DOM manipulation language and think of
document.getElementById('myDiv').innerHTML = 'Hello World';
instead of what it has become today.I still hate it though for sorting arrays with only number types lexically:
[1,2,10,20].sort(); //[1,10,2,20]In fact, your example suffers from the same problem: It sorts in descending order (20,10,2,1) instead of ascending (1,2,10,20).
Telling JS to use a TypedArray [Int8,...,BigInt64] instead can solve this without remembering and providing your own comparator:
Float64Array.from([1,2,10,20]).sort(); //[1,2,10,20]I will concede that I failed to write a function definition, thanks for catching that. I guess I unintentionally refactored the outer function away because development brain took over? Sloppy on my part, regardless.
The point was that modern JS is more convenient to use: Const/let, arrows, classes, proxies, async/await, generators, destructuring, default/rest/spread parameters, etc.
Even if you discard const/let/arrows as merely syntactic improvements (which they are not), you should not ignore the others - unless of course they are all syntactic improvements with added features at which point "syntax" lost its "meaning".