+ 4

What's happening?

I write below code in javascript code playground. var a = 1; name = (a == 1); console.log(typeof name); It shows String How? Variable name should be set with true boolean. Please explain me. why it's happening?

27th Feb 2018, 5:08 PM
UnknownYmous
3 Answers
+ 7
Your problem is that 'name' is already a variable outside of your code. It's referencing the property of the global object 'Window.' Basically, you're messing with 'Window.name' in your code, and it's a string variable.
27th Feb 2018, 5:29 PM
Fata1 Err0r
Fata1 Err0r - avatar
+ 4
Yes Jakob Marley. You are right.
28th Feb 2018, 12:07 AM
UnknownYmous
+ 2
is it allowed to do that kind of comparison when defining a variable? I don't know if that's the case, but I think its worth checking out.
27th Feb 2018, 5:17 PM
storm
storm - avatar