3 ms·
Usually it's awful. I wish JavaScript had if else expressions. Sometimes it can help to break up the lines with indents if you need a single expression: var
by lyjackal 7y ago
Usually it's awful. I wish JavaScript had if else expressions. Sometimes it can help to break up the lines with indents if you need a single expression:
var myvar = foo < bar
? bar
: bar < baz
? baz
: 0
- _jsdw 7y agoI settled on this a while ago which I think is perfectly readable: const myvar = foo < bar ? bar : bar < baz ? baz : lark < 10 ? lark : 0
- piaste 7y agoI would format that as either: var myvar = foo < bar ? bar : bar < baz ? baz : 0 or: var myvar = foo < bar ? bar : bar < baz ? baz : 0
- Avi-D-coder 7y agoYour wish can come true. Take a look at this stage 1 of the TC39 proposal. https://github.com/tc39/proposal-do-expressions https://github.com/tc39/proposal-do-expressions