What is the difference between using “let” and “var”?
It can be said that a variable declared with var is defined throughout the program as compared to let.
An example will clarify the difference even better
Example of var:
Input: console.log(x); var x=5; console.log(x); Output: undefined 5