3 ms·
The ternary operator can be nice for conciseness and to ensure a variable has been assigned to when the language doesn't check that for you e.g. var x = co
by seanwilson 9y ago
The ternary operator can be nice for conciseness and to ensure a variable has been assigned to when the language doesn't check that for you e.g.
var x = condition ? 1 : 2;
vs
var x;
if (condition)
x = 1
else
x = 2
I miss being able to write code like this in languages like OCaml:
let x =
if (condition) then
// more lines of code
1
else
2
- girvo 9y agoHeh your OCaml example is why I adore Nim, and any other languages that "expression all the things!" -- even modern JavaScript is decent on this front with 'ramda' and my favourite helper library @unction: https://github.com/krainboltgreene/unction.js/blob/core/README.md https://github.com/krainboltgreene/unction.js/blob/core/READ... Between those two, consise readable functional JS code based entirely around expressions is simple to achieve. It's genuinely made me happy to be back in JS land