In this topic, we will demonstrate how to use some of the functionalities of ES2015, which may be useful in everyday JavaScript coding and which will also be useful to simplify the examples presented in the following chapters of this book.
Among the functionalities, we will cover the following:
- Variables with
let
andconst
- Template literals
- Destructuring
- Spread operator
- Arrow functions using
=>
- Classes
- Modules
Until ES5, we could declare variables in any place in our code, even if we overwrote the variables declaration, as in the following code:
var framework = 'Angular'; var framework = 'React'; console.log(framework);
The output of the preceding code is React
, as the last variable declared, named framework
, was assigned this value. In the previous code, we had two variables with the same name; this is very dangerous and might drive the code to an incorrect output.
Other languages, such as C, Java, and C#, do not allow this behavior...