Posts

Showing posts from 2019

JavaScript - ES2017 (aka ES8)

The ES2017 ECMAScript 2017, edition 8 of the ECMA-262 Standard (also commonly called  ES2017  or  ES8 ), was finalized in June 2017. Compared to ES6, ES8 is a small release for JavaScript, but still it introduces very useful features: String padding Object.values() Object.entries() Object.getOwnPropertyDescriptors() Trailing commas in function parameter lists and calls Async functions Shared memory and atomics String padding The purpose of string padding is to  add characters to a string , so it  reaches a specific length . ES2017 introduces two  String  methods:  padStart()  and  padEnd() . padStart ( targetLength [ , padString ] ) padEnd ( targetLength [ , padString ] ) Sample usage: 'abc'.padStart(4) // ' abc' 'abc'.padStart(6) // '   abc' 'abc'.padStart(6,'xyz') // 'xyzabc' 'abc'.padEnd(4) // 'abc ' abc.padEnd(6) // 'abc   ' abc.padend(6,'xyz') // 'a

JavaScript - ES2016 (aka ES7)

The ES2016 ES2016, officially known as ECMAScript 2016, was finalized in June 2016.  ES2016 is a tiny release for JavaScript, containing just two features: Array.prototype.includes Exponentiation Operator Array.prototype.includes() This feature introduces a more readable syntax for checking if an array contains an element. With ES6 and lower, to check if an array contained an element you had to use  indexOf , which checks the index in the array, and returns  -1  if the element is not there. Since  -1  is evaluated as a true value, you could  not  do for example if ( ! [ 1 , 2 ] . indexOf ( 3 ) ) { console . log ( 'Not found' ) } With this feature introduced in ES2016 we can do if ( ! [ 1 , 2 ] . includes ( 3 ) ) { console . log ( 'Not found' ) } Exponentiation Operator The exponentiation operator  **  is the equivalent of  Math.pow() , but brought into the language instead of being a library function. Math . pow ( 4 , 2 ) ==

JavaScript - ES2015 (aka ES6)

The ES2015 Since this long time passed between ES5.1 and ES6, the release is full of important new features and major changes in suggested best practices in developing JavaScript programs. To understand how fundamental ES2015 is, just keep in mind that with this version, the specification document went from 250 pages to ~600. In this blog, we describe the most important changes. Arrow Functions A new  this   scope Promises Generators let   and  const Classes Constructor Super Getters and setters Modules Importing modules Exporting modules Template Literals Default parameters The spread operator Destructuring assignments Enhanced Object Literals Simpler syntax to include variables Prototype super() Dynamic properties For-of loop Map and Set New String methods New Object methods Arrow functions Arrow functions since their introduction changed how most JavaScript code looks (and works). Visually, it’s a simple and welcome change, from: cons