Useful ES6 features
ES6 was released in 2015, and it introduced a lot of new features. ECMAScript is a standardized scripting language, and JavaScript is one implementation of it. In this section, we will go through the most important features released in ES6 that we will be using in the following sections.
Constants and variables
Constants, or immutable variables, can be defined by using a const
keyword, as shown in the following code snippet. When using the const
keyword, the variable content cannot be reassigned:
const PI = 3.14159;
Now, you will get an error if you try to reassign the PI
value, as indicated in the following screenshot:
The scope of const
is block-scoped. This means that the const
variable can only be used inside the block in which it is defined. In practice, the block is the area between curly brackets {}
. The following sample code shows how the scope works:
let count =...