ES6 JavaScript Concept
1. Block Binding
When we declare or set a value or variable this time usually bindings occur. Where your variables are actually created depends on how you declare them we use var, let, and const to declare or assign a variable.
2. Var Declarations and Hoisting
var are hoisted to the top of the function or global scope if declared outside a function.var declarations are treated as if they are hoisted to the top of the function or to the global scope if they are declared outside a function.
3.Block-Level Declarations
We know Variable declarations using let or const’ are not hoisted to the top of the enclosing block which can limit the variable’s scope to only the current code block. But if you want the variables are available to the entire block then you can declare the variable using let or const first in the block.
4.Block Binding in Loops
Block level is very useful when dealing with loops in javascript. Its best practice to use let instead of var .
5.Global Block Bindings
Global scope behavior for var is different than let and const. when var is used in the global scope, a new global variable is created, which is a property on the global object (window in browsers), but if you use let or const in the global scope, a new binding is created in the global scope but no property added to the global object (window in browsers). That mean for var you can accidentally overwrite an existing global, but if you use let or const you cannot overwrite.
6. Emerging Best Practices for Block Bindings
During ES6 development, the convention was to use let instead of var and use const to limit the modification. But as more developers migrated, developer following a convention that use const as default and use let when you know the variable value may change.
7. Functions with Default Parameter Values
ES6 function make easier way to pass default parameter values when parameter is not passed when call the function.
8. Working with Unnamed Parameters
ES6 introduces the rest parameter to make it easier to work with unnamed parameters. The rest parameter allows any number of arguments as an array.
9. Arrow Functions
ES6 allows an alternative way to write shorter syntax named arrow function compared to traditional function expression.
10. The Spread Operator
The … spread operator is useful for many different tasks including following:
- Copying an existing array
- Merge or combine arrays
- Call function without apply
- Use in Math Functions
- Use in destructuring
- Use array as arguments
- adding to state in React
- Convert arguments or NodeList to Array