Does Javascript / ES6 support the Elvis operator?
Example:
var x = (y==true) ?: 10;
Example 2:
var debug = true;
debug ?: console.log("Value of x:" + x);
No, but you can just use || or &&, seems to perform same function.
var debug = true;
debug && console.log("debug mode on ");
debug || console.log("debug mode off");
The short answer to your answer is "No". There is no Elvis operator in javascript. But you can achieve the same behavior in a few different short ways like so:
Using plain ternary operator:
var x = y ? 10 : null;
Or using a simple 'if' for just a single output:
if (debug) console.log("Value of x:", x);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With