Today I Learned

hashrocket A Hashrocket project

CoffeeScript doesn't have a ternary operator

CoffeeScript has no ternary operator! This blew me away, since CoffeeScript is so similar to Ruby.

In Ruby, a ? b : c translates to: Is a true? Ok, then return b, otherwise I'll return c.

In CoffeeScript, a ? b : c translates to pure madness. If a is not null or "undefined", return a. Otherwise, return an object literal ({ b: c })...!?!

That's instead of using a ternary (which doesn't exist in CoffeeScript), call it a day with:

if a then b else c

See More #javascript TILs
Looking for help? At Hashrocket, our JavaScript experts launch scalable, performant apps on the Web, Android and iOS. Contact us and find out how we can help you.