Difference between var and let

what is the difference between var and let

difference between var and let lies in the scope. var is function scoped and let is blocked scoped. you can read more about it here

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.

Variables declared by “var” keyword are scoped to the immediate function body (function scope) while “let” variables are scoped to the immediate enclosing block denoted by {…} (block scope).

Variable declared with var keyword can be re-declared and updated in the same scope while variable declared with let keyword can be updated but not re-declared.

Variables defined with let are hoisted to the top of the block , but not initialized. This means that the block of code is aware of the variable, but it cannot be used until it has been declared. So, using a let variable before it is declared will result in a ReferenceError.