#different between with or without a '' lat ''

9 messages · Page 1 of 1 (latest)

trim summit
#

Hi, does everyone know, why don't use "let" in front of cards array and sum?
like the image
thank you for your help!

glass idol
#

I'm guessing from the comment - both those variables were created outside of that function. Since they've already been declared, you don't need the 'let' anymore, you're just reassigning the value in the function.

silk patio
#

Const can’t be re assigned but let can be. Const is the short form of constant usually used when value or the variable remain consistent. Let comes from assumptions you can declare let name and use it anywhere in the code,

glossy tulip
# trim summit

Right, you also can't, not even "need to". As you marked out those variables, they are so called "global" variables, because they were created in the top-most "level" (also so called scope) of code; by doing so, those variables are reachable and usable from within anywhere in code, like the startGame function does, and so sharing their value across the whole program. But you can't put let in front of them again in order to reach those global variables, just use their names.

If you would use let eg within a function, that would be called shadowing of a variable, which is legal, but has a different effect (of creating a new local variable of that same name, but effectively blocking yourself out to have access to that global variable in that function).

Just best try it for yourself in some new scrim, just this of having a global variables, accessing them in a function, etc. You won't break anything, you just get the idea. For testing JS language concepts, I use https://runjs.app/ .

raven nacelle
#

Variables declared outside of functions become global (have a global scope). You can access them from all your functions. If you create a new variable with the same name inside a function, that function will use it and not "see" the global one.

glossy tulip
raven nacelle
silk patio
#

👍