3 ms·
var and let tell the compiler the scope in which it should declare the variable (oversimplifying). If var or let are not present, the variable is declared in th
by jacobwilliamroy 7y ago
var and let tell the compiler the scope in which it should declare the variable (oversimplifying). If var or let are not present, the variable is declared in the global scope; unless you're in strict-mode, then you get a scolding.
So var and let are only tangential to the whole declaration process and only indicate the scope in which the variable is bound.
I feel confused. Why do you want your assignment statements to be prefixed with var's and let's?
- z3t4 7y agoif you put var in-front you don't have to worry about reassigning a variable from parent scope. You also make assignment and comparison semantically different, example var foo=1; vs foo=1 if(foo=1) and it's thus easier to spot bugs and understand the code.