4 ms·
alternatively: // Would run console.error with the Error object (alert(x) ?: console.error);
by Jarred 8y ago
alternatively:
// Would run console.error with the Error object
(alert(x) ?: console.error);
- lifthrasiir 8y agoThis is indeed a form supported by GNU C extension [1] (but `?:` is not a single token, so `? :` is permitted). [1] https://gcc.gnu.org/onlinedocs/gcc/Conditionals.html#Conditionals https://gcc.gnu.org/onlinedocs/gcc/Conditionals.html#Conditi...
- azernik 8y agoYou may know this, but others may not: this is an actual thing, and is called the Elvis Operator (think the hair). https://en.wikipedia.org/wiki/Elvis_operator https://en.wikipedia.org/wiki/Elvis_operator Shockingly, this is actually accepted by GCC's C dialect! And PHP! By the simple implementation expedient of making the second operand of the ternary operator optional.