Closed samreid closed 10 years ago
I can live with it either way. I've seen style guides for other languages (C, C++) that recommend against the ternary operator because some feel that it's more difficult to read and a 'baroque' language feature.
If you do use the conditional (ternary) operator… With the single-line form, I prefer to put parentheses around the expression to improve readability. Especially if the expression involves more than one operator.
var numToCreate = ( intensity < cycleLength ) ? 1 : Math.floor( 0.05 * intensity );
I agree, the ternary operator looks a little nicer in this case, and I went with the parenthesis around the conditional expression. Assigning to @samreid for review
Looks great, closing.
It is a stylistic preference, but I recommend in cases like this:
To use the ternary operator like so:
or