In this session, you learned about:
- ECMAScript, which is a trademarked scripting language specification standardized by ECMAScript International. This specification governs JavaScript language by providing a set of rules and guidelines which JavaScript must conform to.
- JavaScript Engine, which interprets and executes JavaScript code in the browser.
- Different releases of ECMAScript specification - involving ES2015 (popularly known as ES6) released in 2015, which brought major changes in the JavaScript language.
- Babel, which is the JavaScript compiler that converts the code written in ES6 (or later versions) to the ES5 code, which is understood by most of the browsers.
You also looked at some of the differences between ES5 and ES6 syntax. Following are some of the points followed by the new syntax in ES6:
- Declaring variables with two new keywords - let and const. The former is used when you wish to change the value of the variable in future and the latter is used when you do not wish to change the value of the variable. Unlike var, the variables declared using let/const keywords are not hoisted.
- Classes, which are syntactic sugar over JavaScript's existing functions and help in achieving what is so-called prototype-based inheritance in ES5.
- Arrow functions, which is a new syntax over traditional functions and are used to write code quickly and more effectively. They also solve some of the problems, as we see with the context w.r.t. 'this' keyword.
- Array methods - map(), filter(), reduce() methods, which are used to iterate over an array and is a much simpler and quicker way to perform operations on an array as compared to its alternative methods.
- The powerful three dots - referred to as the spread operator as well as the rest parameters, depending upon the context in which they are used. When used as spread operator, they are used to segregate an array into its individual elements. When used as the rest parameters, they are used to treat individual arguments passed to a function as a combined array in the function parameters.
- Template Literals, which are better way of concatenating string literals.
- Ways of destructuring an array or an object to extract the its individual elements or keys.
- import and export keywords - used for importing and exporting modules (including variables, functions, classes, etc.) defined in one file to be used in another file so as to maintain code reusability and reduce redundancy.