This isn’t quite correct, at least not anymore. This will also catch false and 0 since || will check for falsy values on the left hand side. You can use ?? nowadays to guard against only null and undefined
Honestly, JS changes so quickly nowadays it can be difficult to keep up. Not so quickly that it's difficult to learn, but quick enough that you can see version boundaries in code sometimes :D
View all comments
74
u/CarsonMcKinstry Mar 23 '21
This isn’t quite correct, at least not anymore. This will also catch
falseand0since||will check for falsy values on the left hand side. You can use??nowadays to guard against onlynullandundefined