2. New methods of declaring variables
The main advantage of using both let and const over var is that when using var variables get scoped to the top of the current function, therefore making the variable available to the whole function.
In contrast, let and const are scoped to their closest block, allowing developers to declare variables within if, while, for and even switch blocks, without worrying about the variable scope leaking outside of that context.
3. Use arrow functions to keep ‘this’ intact
There are two main ways of writing arrow functions:
One-liners have only one expression and return value of that given expression, without the need for curly braces.
Whereas Multiple-liners, on the other hand, have curly braces and the return keyword will be used explicitly.
4. Replace ‘for’ loops with ‘map’
Let’s say we have an array of numbers and we want to produce another array by doubling all of the numbers from the first array. One method is to do by declaring an empty array, write a for loop, and set a number in the second array by looking up the index on the first array and doubling it.
We can use a more concise solution by mapping an array to another array:
[1, 2, 3].map((num) => num * 2); // [2, 4, 6]
5. Replace ‘for’ loops with ‘filter’
Let’s suppose we have an array of numbers and we want to produce another array containing only even numbers from the first array. One way of doing this would be to declare an empty array, write a for loop, and write an if statement to check if the number at the index is even.
For example, we could use the filter method available for arrays:
[4, 7, 2, 3].filter((num) => num % 2 === 0); // [4, 2]
6. Redux: State of management for all
state and immutability.