- Get link
- Other Apps
Let and Const In javaSctipt earlier we were using var which is a functional or global scope. Now in Es6 We have new way to assign variable which are let and const which are block scop or local scope. Let Variable: Let is a block scope varibale whose value can be changed. Const Variable:Const is a block scoper variable whose value can not changed What is function/global scope and block scope? Function scope work on the entire code whereas block level code works inside only a perticular block in which the variable is written. Because of this the error will be less as we can use the same variable multiple times and assign new value without disturbing the earlier ones. For Expample in this function scope code we will see the how var works var name = "shivam"; if(name.typeof= string){ var name = "Neha"; console.log("i am"+ name);