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. 

 

ecma2016
Let's start with what's new in 2016 - not a lot really. 

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:

function in(el,array){
 for(x in array){
  if( el===x) return true;
 };
 return false;
}

You can now write:

function in(el,array){
 return array.includes(el);
}

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: 

function in(el,array){
 return  (arr.indexOf(el) !== -1
}

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:

z= Math.pow(x,2) + Math.pow(y,2);

At long last you can now write raise to a power using the old Fortran ** operator and formulas look a lot better for it:

z= x**2 + y**2;

Of course for small powers it still usually better to write  x*x for x squared:

z= x*x  + y*y;

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.

ecma2016

More Information

ECMAScript® 2016 Language Specification

Related Articles

JavaScript The Language With Two Names    

The JavaScript Encyclopedia Work In Progress 

JavaScript Added To Oxford English Dictionary 

JavaScript 6 EcmaScript 2015 Final Approval 

JavaScript 20 Years Old Today 

 

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, FacebookGoogle+ or Linkedin

Banner


Running PostgreSQL Inside Your Browser With PGLite
18/03/2024

Thanks to WebAssembly we can now enjoy PostgreSQL inside the browser so that we can build reactive, realtime, local-first apps directly on Postgres. PGLite is about to make this even easier.



Crazy Clocks
10/03/2024

It's that time again when the clocks change and  time is of the essence and I indulge my interest in crazy clocks. I am always surprised that there are still new ideas for how to display the time [ ... ]


More News

 

raspberry pi books

 

Comments




or email your comment to: comments@i-programmer.info

Last Updated ( Thursday, 23 June 2016 )