Can I write the if else
shorthand without the else
?(if else
没有else
我可以写if else
速记吗?)
var x=1;
x==2 ? dosomething() : doNothingButContinueCode();
I've noticed putting null
for the else works (but I have no idea why or if that's a good idea).(我注意到将else设置为null
可以使其他作品有效(但是我不知道为什么或如果那是个好主意)。)
Edit: Some of you seem bemused why I'd bother trying this.(编辑:你们中有些人似乎感到困惑,为什么我要尝试这个。) Rest assured it's purely out of curiosity.(请放心,这完全是出于好奇。) I like messing around with JavaScript.(我喜欢弄乱JavaScript。)
ask by Nikki translate from so
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…