Why does it work like this? Python VS JS

The code is the same, but the results are different. It seems to be because of let, but why is this happening? JS has some other type of global and local variables?

Hello @aleksandrtitov, welcome to the forums! Since you’ve used let lightWaves in the if block, I suspect JS has created a new local variable (lightWaves) inside the if block, which is different to the lightWaves variable in the function scope. This isn’t the case in Python as you don’t have anyh keywords for defining variables (let, const, etc) so that isn’t a problem…

1 Like

Hi,
You’re right, it’s the let. That is causing JS to create a new variable that is purely local just to the block of code associated with the if statement (i.e. there are levels to ‘localness’).
In other words, be careful what you name your variables and where you declare them.

1 Like