30 Day JavaScript Learning Challenge: Day 14

Day 14 started up Chapter 4 of Eloquent Javascriot. This portion started up with arrays, which got me into a tangent on playing with passing an array to a function. Take for instance:

> Math.max(1, 2, 3);
3

You'd think that the following would work:

> var arr = [1, 2, 3]
> Math.max(arr);
NaN

Welcome to JavaScript, where the crushing of your expectations makes sweet wine.

Of course there's ways around this. Aaron Crane explains Math.max in Javascript and a hack to work around it.

Eventually JavaScript should have a spread operator (...) but that's proposed for ECMAScript 6.

Of course Python managed to figure out how to make this work without major hacking. Perhaps at some point it will be.


links

social