| Var Declarations and Hoisting
Variable declaration will applicable if the variable is hoisted on the top of the function or it will be treated global scope if they are declared outside a function.
We see that, Variable “a” Declaration top of the function .the value “a” of the variable access function scope and outside but var “b” declared function scope is not accessed outside then show an error.
| Let Declarations
The let and var declaration syntax are same. You can use let instead of declaring var. And if you do this you have to remember that the scope of the variable will remain into the current block because var is hoisted on the top of the function but let is not hoisted
When we declared a variable with Const, we can’t change this value that means this value is never been changed as it is constant value.
The try-catch construct has two main blocks: Try and then Catch
It works like this:
- At first, the code Try is executed.
- if there is no error then the catch part is ignored, the try part goes on, and the catch part is skipped.
- if there is a show error, try part execution stopped and catch part detect error details about what happened.
|Block Binding in Loops
we See that , “i” is accessible here because we declare using var but “i” is not be accessible here because we declare using let
|Emerging Best Practices for Block Bindings
|Functions with Default Parameter Values
ES6 make it easier to pass default parameter values when parameter is not formally passed when call the function. In ES5 are not available in this features default values parameter passed.
|Global Block Bindings
Global scope behavior for var is different than let and const. For example 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.
When var is being used:
When var is being used:
|Working with Unnamed Parameters
| The Spread Operator
Spread Operator takes in repeat (e.g an array) and expands it to list of arguments.
The … spread operator is useful for many different tasks including following:
- opying 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
| Arrow Function
ES6 allows an alternative way to write shorter syntax named arrow function compared to traditional function expression.
ES6 allows block-level functions which are hoisted on top of the function or hoisted into the global scope..