Anyone have a good trick to remember the standard ternary syntax?
Specifically whether the '?' or ':' comes first. I have consistently gotten this backwards over the years.
Anyone have a good trick to remember the standard ternary syntax?
Specifically whether the '?' or ':' comes first. I have consistently gotten this backwards over the years.
"?" is a question mark so it means "if".
A colon means, "now it comes", "then do".
The good thing about the ternary operator is that you are not forced to use it, especially if you are having problems remembering the syntax. Just use an if-statement which is more readable most times.
And no - the ternary has no better performace then an if-statement.