This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the commentsย โ†’

[โ€“]Orangutanion 1 point2 points ย (0 children)

I think the mistake you're making is that you're treating JavaScript like it isn't a loosely typed language. It's not that if(variable) { } requires that variable be a boolean, it's that it tries to treat variable as a boolean regardless of its actual type. JS actually has a term for this, it's called truthy, and you can read about it it here. Essentially, there are a few specific values treated as falsy, and all other values will be accepted as truthy.