Scope Question (Unit 4.6: Scope--Block Scope II)


can someone explain why this code logs both ‘Northern Lights’ and ‘Moonlight’?
i expected it to log only northern lights?

lightWaves defined on line 5 only exist within the if block, so line 6 will print northern lights

so after the if block (line 8) the value will again be Moonlight, given this is outside the scope of lightWaves defined of line 5

1 Like

Thanks that makes sense!!

it has to do with the scope, the let varible is first declared with one value and then printed out… then it changes back to the orignal value you declared…

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.