why (!null) is true? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

why (!null) is true?

if(!null) echo "true"; else echo "false"; //output : true

30th May 2017, 2:47 PM
kaushal singh
kaushal singh - avatar
3 Answers
+ 21
Default boolean value of null is false and ! converts it to true
30th May 2017, 2:49 PM
Valen.H. ~
Valen.H. ~ - avatar
+ 4
Think of ! as "is not", it helps (that's how CoffeeScript works too, and I love it). So, this: if(!null) Means: if is not null
30th May 2017, 4:02 PM
Taija
Taija - avatar
+ 2
thanks.
30th May 2017, 2:50 PM
kaushal singh
kaushal singh - avatar