dayuloli
dayuloli

Reputation: 17021

Why does CoffeeScript not support `==`?

I am learning CoffeeScript and am using js2.coffee to convert my Javascript file to CoffeeScript. One some lines, it warns me that

Operator '==' is not supported in CoffeeScript, use '===' instead.

What is the rationale behind that? Why does CoffeeScript not support ==?

Upvotes: 0

Views: 212

Answers (2)

faiakism
faiakism

Reputation: 67

Actually CoffeeScript compiles == to JavaScript's === (and != to !== as you can see in the documentation).

So bottom line yes, it doesn't support it. I guess it is because == does type conversion before checking equality if the operands are of different type. This conversion is a practice that has been frowned upon because of its unexpected results and its performance.

There is much discussion online on the issue of == vs ===. MDN docs helped me get a better understanding on the issue.

Upvotes: 1

user229044
user229044

Reputation: 239422

For the same reason that most Linters warn you against using it.

It's a strangely implemented operator with surprising side-effects.

"\n\t" == false
// => true

There are many things written on the topic, but most notably the == operator made Douglas Crockford's list of things to avoid.

Upvotes: 1

Related Questions