Day 5: Let
-
-
JairAviles Asked to answer 9 years ago The difference is just scoping. var is scoped to the nearest function block (or global if outside a function block), and let is scoped to the nearest enclosing block (or global if outside any block), which can be smaller than a function block.
Also, just like var, variables declared with let are visible before they are declared in their enclosing block, so the purpose of let statements is only to free up memory when not needed in a certain block.
https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Statements/let
-
I am a C user who tries to learn javascript. Generally implementing software using global variables are NOT safe.
I see many examples use "var" and its scope seems "ignore bracket" in javascript.
So Here is the question, is using "var" instead of "let" common and how can I use it safely?
Add Reply Preview cancel