News for hackers. Stuff that matters.
Re:Writing Eloquent JavaScript Without CoffeeScript by xer0 on Friday December 09, 2011 @11:50AM (#3334400)
"I find if(...){} much more readable."

Not only is it more readable, it's more correct in the example given.

"if" is a statement. The ternary operator (?:) is an expression, that returns a value. The semantics are different, and using the ternary operator "merely" to replace an if statement, especially where no assignment of the ternary operator's return value is made, is a code smell.

The ternary operator is great if you're replacing a simple "if something assignment to X else other assignment to X." Any other use is questionable.

There are no comments on this comment yet.