Monday, 16 September 2019

difference between let and var

In script you can declare a variable with multiple time.

for example 
var a=20;
var a=30;
console.log(a); //30

but with let you cant redeclare a same variable name.
exp

let data=20;
let data=30;
console.log(data);
//you will get error.
Identifier 'a' has already been declared.
With let you can reassign variable 
like 
let data=20;
data=40;

No comments:

Post a Comment