Sign In Solutions interview question

What's the difference between var and let?

Interview Answer

Anonymous

18 Aug 2020

Var: It is a function scoped means a variable declared with var is defined throughout the program scope. Also var keyword are hoisted means it is initialized with undefined before the code is run. It creates a property on the global object, which can be accessed using windows object. Let: It is a block scoped means a variable declared with let is defined only within the curly braces { }. We can not redeclare the same variable in the same scope.