Ranter
Join devRant
Do all the things like
++ or -- rants, post your own rants, comment on others' rants and build your customized dev avatar
Sign Up
Pipeless API
From the creators of devRant, Pipeless lets you power real-time personalized recommendations and activity feeds using a simple API
Learn More
Comments
-
Yes, but in most cases it does string conversion. Because of this you get unforgettable moments like 2 == [[[[[2]]]]] -> true
-
Also would it not be correct thay booleans are 0 and 1? False and true?
So your saying is 1 ==2? False? It's funny because it's
!false -
2 is truthy. It's true that 2 exists. That's what Boolean(2) means.
But it isn't equal to the value true.
It's called type casting and it's how js is supposed to work. Understand and embrace the flexibility. -
johnSnow587y@hashedram Boolean(2) Means typecasting 2 into boolean and js typecasts 2 into true... And '==' is supposed to do type conversion before comparing quantities still
2 != true... -
@johnSnow That's because of a genuinely fucking stupid concept called type coercion that js tends to do. It's one of the bad parts that even Crockford acknowledges.
== Just ignores type right out. But Boolean(x) kind of does some fucky nudging.
If you search for js type coercion, you'll get many other retarded examples, most worse than this.
No excuses for this one. Still one can learn to avoid coercion most of the time. -
johnSnow587y@hashedram you are absolutely right i think i have given a better explanation for the same in
https://devrant.com/rants/1446736/...
What the Fun Javascript!!!
'==' in Javascript is supposed to do type conversions, before comparing the two items.
Then...!!
rant
javascript
random