Re:New ES2019 JavaScript features
by robinson7d on Thursday September 26, 2019 @08:21PM
(#21087166)
It’s more than simple ternary, for example:
`response?.data?.users?[0]`
To get the first user from a server response would be significantly longer if you wrote three nested ternary operators.
Re:New ES2019 JavaScript features
by james-mcelwain on Thursday September 26, 2019 @08:07PM
(#21087073)
x ?: y
is shorthand for x != null ? x : yIn JavaScript you can simply use the logical or operator
x || y
This is not equivalent. It will result in y if x is any falsy value (like false, empty string, or 0), not just if x is nullish.
In which languages does ?: not work that way?
For example in PHP, it works exactly like you describe.
I think that’s exactly what the nullish ?? Operator is.
You can write x ?? y
Which is x !== null and x != undefined ? x : y
Re:New ES2019 JavaScript features
by james-mcelwain on Friday September 27, 2019 @11:42AM
(#21093170)
Kotlin.
This is already there: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Refe...