Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

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


Kotlin.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: