null coalescing operator for javascript?
Posted
by Daniel Schaffer
on Stack Overflow
See other posts from Stack Overflow
or by Daniel Schaffer
Published on 2009-01-24T18:18:02Z
Indexed on
2010/04/07
2:33 UTC
Read the original article
Hit count: 435
I assumed this question has already been asked here, but I couldn't find any, so here it goes:
Is there a null coalescing operator in Javascript?
For example, in C#, I can do this:
String someString = null;
var whatIWant = someString ?? "Cookies!";
The best approximation I can figure out for Javascript is using the conditional operator:
var someString = null;
var whatIWant = someString ? someString : 'Cookies!';
Which is sorta icky IMHO. Can I do better?
© Stack Overflow or respective owner