ECMAScript 2016 Approved |
Written by Ian Elliot |
Thursday, 23 June 2016 |
That's probably JavaScript 1.9 or ES7 to you. If you are puzzled by the name it is probably because you haven't realized that ECMAScript has gone over to a yearly release schedule, which might not be a good thing at all.
There are two small new features. You can now perform a functional programming like search of an array for a particular element. That is instead of:
You can now write:
That is, array.includes(el) is true if el is an element of the array. Of course you could have done something similar before using indexOf:
However, includes is more expressive of what you mean. There are also some minor differences between indexOf and includes. For example, it will match NaN and undefined. Useful but hardly a revolution. The second new feature is long overdue if you write any sort of numerical number crunching program. JavaScript doesn't have a "raise to the power" operator. A very common error, committed by programmers who simply cannot believe that a language doesn't have an exponential operator, is to write x^2 for x squared. This might appear to work if you don't check the result because the ^ operator is exclusive OR. The correct way to raise to a power is to use Math.pow(x,2) which doesn't look good and looks even worse when you use it in a formula, for example:
At long last you can now write raise to a power using the old Fortran ** operator and formulas look a lot better for it:
Of course for small powers it still usually better to write x*x for x squared:
So that's it - ES 2016 summed up. Welcome additions but not much to show for a year's worth of deliberations. The whole point seems to be that small incremental changes are the new normal for JavaScript, instead of having to wait years for a mega upgrade that might not even happen. This seems sensible, but there is a downside. Now you have to worry if your code is ES 2015 or 2016 compatible. Is it really worth having a JavaScript engine support issue for just two small additions? With big changes you can make a conscious decision to write in a clear subset of the language small changes mean you have a whole set of things to keep in mind. Imagine in a few years time when you need to look at a "can I use" matrix for ES2020. Of course, in an ideal world all JavaScript engines would upgrade as soon as the standard was out and you could write the latest code and expect it to run anywhere. But the world isn't ideal. More InformationECMAScript® 2016 Language Specification Related ArticlesJavaScript The Language With Two Names The JavaScript Encyclopedia Work In Progress JavaScript Added To Oxford English Dictionary JavaScript 6 EcmaScript 2015 Final Approval
To be informed about new articles on I Programmer, sign up for our weekly newsletter, subscribe to the RSS feed and follow us on, Twitter, Facebook, Google+ or Linkedin.
Comments
or email your comment to: comments@i-programmer.info |
Last Updated ( Thursday, 23 June 2016 ) |