ECMA is an international organization that defines the standards of computer systems and communication systems. This organization started its work in Europe in 1961 and is in charge of defining standards, and since 1994 it has been known by its current title, ECMA.
ES6 is a relatively new standard, released in 2015, and it supports many new features. The standard is technically called ES2015, and each subsequent annual version is also identified by the year of release. But in any case, most people call it ES6, and that’s why we use the same title.
Table of Contents
How to use ES6 structure?
ES6 has practically been supported in many places and the only major problem is in Internet Explorer. So although you can start writing ES6 style, you can’t be sure that it will behave the same way on everyone’s browser.
Today, ES6 is typically compiled to the ES5 framework using a tool like Babel. Babel is a compiler that converts the development code (the code written in ES6 with all its features) into the code that runs on the production site, and in most cases, it is bundled and minified with the help of webpack.
The way it works is that you have some js files in your development environment. You write you are free to use any nice ES6 framework you like. But instead of running this code directly, you configure Webpack to load JS files with Babel. In most cases, you need to run webpack-dev-server so that this conversion is done automatically when you make changes.
New features of ES6
- Reflection (**)
- default values
Safari 10 and Edge 14 are the first browsers to fully support ES6.
The let command allows you to define a block scope variable.
The exponentiation operator (**) raises the first operator to the size of the second operator.
Default parameter values
ES6 allows function parameters to have default values.
The find() method returns the value of the first array element that a test function puts.
The findIndex() method returns the index of the first array element that passes a test.
New numerical properties
ES6 has added the following properties for the number object:
New numerical methods
ES6 adds two new methods to the numeric object:
- isInteger() method
If the argument is an integer, true is returned.
A safe integer is an integer that represents double precision. If the argument is a safe integer, the Number.isSafeInteger() method returns true. Safe integers are all integers from – (1 – 253) to + (1 – 253). This is safe: 9007199254740991. This is not safe: 9007199254740992.
New public methods
ES6 also introduced two new public methods:
- () isFinite
If the argument is NaN or infinity, this method will return false and otherwise, the result will be true:
If the argument is NaN then this method returns true, otherwise false.
Arrow functions allow a short syntax for writing function statements. You don’t need function keywords, return keywords, and curly brackets. Arrow functions do not have this functionality. They are not suitable for defining object methods. Arrow functions are not incremented. They must be defined before they can be used. Using const is safer than using var because a function expression is always a constant value. You can only remove return words and curly brackets if the function is a single statement. For this reason, it may be a good habit to always keep them.