Use of `let` outside of block level?
At the end Guil mentions that let should be used at the block level. Does this mean we should not use
let outside of a function block?
What if we have a variable that will change and it's outside of the block? Should we use
let in this case?
Or would we only want a variable to change when it's inside of a block and never at the root level?
Thanks to anyone who can help clarify! =)
Ari Misha19,229 Points
Hiya there! "let" keyword in ES6 binds the variable to its corresponding scope. Combing let with arrow functions, gives you a desired result. If we define a variable using let keyword in global scope, you can override it if you want.But thats where const keyword comes in. With const keyword, you can declare the value again even if its in the global scope. I hope it helped!
I don't know if this definition that i found can help you to understand that statement but i think here is a great explanation of the let variable in general.
The rule of thumb here is: if the variable is mutable use let. if the variable in immutable use const. using let outside of a block level function means it would be a global variable and can change.