9

What the Fun Javascript!!!

'==' in Javascript is supposed to do type conversions, before comparing the two items.

Then...!!

Comments
  • 3
    Yes, but in most cases it does string conversion. Because of this you get unforgettable moments like 2 == [[[[[2]]]]] -> true
  • 1
    @johnSnow please swear properly. Let it out. You'll feel better.
  • 1
    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
  • 6
    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.
  • 0
    @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...
  • 1
    @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.
  • 0
    @hashedram you are absolutely right i think i have given a better explanation for the same in

    https://devrant.com/rants/1446736/...
Add Comment