Day 5: Let
-
[deleted] 9 years ago I started a GIT branch for those who need a little help let me know if you need explanations added as well https://github.com/giannioudis/7-Days-of-JavaScript
-
ameyb2018 6 years ago //Global variable index has been declared and initialized //Edit the code below. console.log("The global index (before for-loop) is : ", index);
for(let index = 0; index < N; index++){ console.log("The local index is : ",index); }
console.log("The global index (after for-loop) is : ",index);
-
paterlini_luca 8 years ago this challange have no sense, I've only changed the name of the variable used for the step in the for loop.
Uselesschallenge
-
Sean83 9 years ago 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?
-
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
-
-
hozefaj 9 years ago Problem is to trivial. Ideally a question which utilizes more of this concept would be better.
Sort 8 Discussions, By:
Please Log In in order to post a comment