+ 3
JS challenge question help
Hello community, I have a question about the following code (function() { let a = b = 3; })(); console.log(typeof a == "undefined"); console.log(typeof b == "number"); Why does first comparison evaluates to true? Doesnt a gets assigned value of b, which is three, because of the associativity? Instead, It looks like it is indeed undefined.
4 Respostas
+ 2
According to MDN
"a = b = 5; // same as writing a = (b = 5);"
It looks as if the let keyword only applies to variable a.
let a = b = 3 || let a = (b = 3)
It also appears that variable b is globally scoped, while variable a is block-scoped inside of the IFIIE, hence the reason both evaluations return true.
I ran the snippet on playground(web and node) and b is globally scoped
(CMIIW)
+ 2
I thought it gets assigned value of 3 and so its typeof then changes to number. Thanks for your help though.
+ 2
I didnt do this code myself, It was created by someone and is a legit question in challenges
0
You're welcome