let result;
while (true){
result = promt("give me a number:");
if (valid(result)){ break; }
}
valid() represents a function which would validate result (to see if result is a number, i was too lazy to implement that, given its not relevant to the question), given let is block scoped, and i want to use result after the loop, i will first need to define the variable outside the block scope of the loop.
maybe not a greatest example in the history of examples, but you need to know its possible to define variable without value, in case you might ever need it
I still don’t understand why it wants me to use true and false instead of something tangible like food. True or false is … some other type of data? I should know this but I can’t remember it
I do remember the word boolean, just no idea what it is…I don’t know how I got thru the exercise for that.
I have some of the methods saved (i’ll never remember those) but I don’t know any other documentation. I’ve reviewed each lesson at least 4-5 times and done them many times over and I feel like I never remember any of it very long or maybe just how to finish the exercise.
in the first example, you define/declare a variable, you don’t give it a value, so the variable will now hold undefined. Then later you update the variable.
in the second example, you give the variable a value
There are cases where this might be useful, but better to save that for later. Otherwise things get too complex right away
so does it means that 1st value of let is now considered as obsolete? why not just replace the value rather than reassigning new one? as of this stage of learning, it’s quite weird to me…is it because it maybe hard to locate in the future so your declaring a new value?
In some cases, replacing might be possible. But there are other times where re-assigning is the way to go.
Sometimes, a concept is taught but might not be clear what the advantages are. That is okay.
lets say you want to prompt the user input, and the input needs to be a number. I don’t want keep all invalid inputs around. So then re-assigning is the way to go