You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I was goofing around with JS weirdness today, and I found this behaviour, which took me some time to explain to myself. Maybe it could be included in the file?
It started off with the basic type coercion, which worked as expected:
1==true// true0==false// true
My initial assumption was that the value is cast to Boolean. For this simple example, that assumption would hold
Boolean(1)// trueBoolean(0)// false
But it broke when trying the following:
1.1==true// false
Given my original assumption, I was a bit confused because I know Boolean(1.1) -> true.
But the true explanation to the first snippet is:
Number(true)// 1Number(false)// 0
Meaning that true/false is cast to and compared as Number.
The text was updated successfully, but these errors were encountered:
I was goofing around with JS weirdness today, and I found this behaviour, which took me some time to explain to myself. Maybe it could be included in the file?
It started off with the basic type coercion, which worked as expected:
My initial assumption was that the value is cast to
Boolean
. For this simple example, that assumption would holdBut it broke when trying the following:
Given my original assumption, I was a bit confused because I know
Boolean(1.1) -> true
.But the true explanation to the first snippet is:
Meaning that
true
/false
is cast to and compared asNumber
.The text was updated successfully, but these errors were encountered: