The difference betweenvar andlet in JavaScript is block scope.
var
When avar is declared outside a block scope, and then re declared inside a block after the first declaration. The value of thevar gets changed after the block scope is over.
//first declaration of var xvarx=10;{//second declaration of var xvarx=5;alert(x);//prints 5}alert(x);//prints 5
let
However by usinglet keyword to declare a variable. the value of the variable doesn't get changed by the subsequent re declaration inside the block.
//first declaration of let var ylety=15;{//second declaration of let var ylety=90;alert(y);//prints 90}alert(y);//prints 15
Top comments(0)
Subscribe
For further actions, you may consider blocking this person and/orreporting abuse