Careful with the definition of scoping here. The 'ifs' and 'for' loops do not create a new scope in JavaScript for just any "declared variable" as it has both "function scope" and (now) "block scope". Also, you aren't really "declaring variables", you are declaring constants. "Variables" declared with const or let have block scope, those declared with var have function scope.
Careful with the definition of scoping here. The 'ifs' and 'for' loops do not create a new scope in JavaScript for just any "declared variable" as it has both "function scope" and (now) "block scope". Also, you aren't really "declaring variables", you are declaring constants. "Variables" declared with
const
orlet
have block scope, those declared withvar
have function scope.Ref: developer.mozilla.org/en-US/docs/W...
I see. Thank you for the clarification.