guys what do they mean by the switch expression is evaluated once someone please explain how the process unfolds i | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

guys what do they mean by the switch expression is evaluated once someone please explain how the process unfolds i

as simple as possible thanks in advance

28th May 2017, 10:26 PM
wazha
wazha - avatar
1 Answer
+ 3
not sure about javascript. But in c++ it looks like this switch(expression) <- this is evaluated once. { ~~ } So if we had int x; cin >> x; switch(1+x) { }; The expression 1+ x would be performed or calculated just the one time. The result is stored and used to compare against the case statements. I assume javascript switch statements operate in a similar way
28th May 2017, 10:56 PM
jay
jay - avatar