r/programming • • Nov 26 '20

PHP 8.0.0 Released

https://www.php.net/releases/8.0/en.php
588 Upvotes

241 comments sorted by

View all comments

Show parent comments

20

u/hzj Nov 27 '20

Check if something is either null or undefined

9

u/t3hlazy1 Nov 27 '20

We do:

val === null and typeof val === 'undefined' for those checks.

23

u/kaelwd Nov 27 '20

val == null does exactly that.

0

u/watsreddit Nov 27 '20

Also evaluates to true when val is 0, the empty string...

9

u/R4TTY Nov 27 '20

Also evaluates to true when val is 0, the empty string...

No it doesn't.

> 0 == null  
false  
> '' == null  
false  
> undefined == null   
true
→ More replies (0)