Skip to content

Comment on Strangest Programming Language Feature?parent

Comments

It's because equality comparisons in CoffeeScript (==, !=, is, isnt) are always compiled into strict (non-type-converting) comparisons (===, !==). [1]

JavaScript doesn't have strict relational operators (>, <, >=, <=), so all relational comparisons undergo type-conversion. [2]

  CoffeeScript: 0 <= "" <= 0           #  True
  JavaScript:   (0 <= "" && "" <= 0);  // True

  CoffeeScript: "" is 0    #  False
  JavaScript:   "" === 0;  // False
[1]: http://coffeescript.org/#operators

[2]: http://www.ecma-international.org/ecma-262/5.1/#sec-11.8

EDIT: Forgot to include 'is' and 'isnt' operators.

AboutSource Built by g1lg1l

Hackerly is an independent reader for Hacker News, built on the public HN API. Not affiliated with Y Combinator.