I know that in PHP 5.3 instead of using this redundant ternary operator syntax: …we can use a shorthand syntax for our ternary operators where applicable: And I know about the ternary operator in JavaScript: …but is there a shorthand? Answer Something like that what you’re looking for, where it defaults if undefined? By the way, this works for a
Tag: conditional-operator
How do you use the ? : (conditional) operator in JavaScript?
What is the ?: (question mark and colon operator aka. conditional or “ternary”) operator and how can I use it? Answer This is a one-line shorthand for an if-else statement. It’s called the conditional operator.1 Here is an example of code that could be shortened with the conditional operator: This can be shortened with the ?: like so: Like all