Boolean Values
1 min readMar 24, 2019
Boolean was named after an English mathematician of the 19th century called George Boolean who invented boolean values false( 0 ) and true( 1 ).
There are two types of Boolean Values:
i-Explicit Boolean Values
ii-Implicit Boolean Values
i-Explicit Boolean Values:
are two keywords TRUE and FALSE.
- They are case insensitive so you can write
true
,TRUE
,TrUE
. - You cannot enclose them in quotes.
‘false’
is not allowed
ii-Implicit Boolean Values:
are referred to truthy
and falsy
values.
Falsy Values:
- Zero as a number or string e.g.
0, 0.0, ‘0’
are considered to be false. - Any Empty String with nothing between the quotes (
‘’, “”
) - An empty array.
- NULL( including unset values )
- simpleXML object created from empty tags .
- Everything else is true.
Truthy Values
- Any number apart from 0, 0.0 or ‘0’ is true ( even -1 is true )
- Any string within quotes (except empty quotes ) is considered to be true. Hence because ‘false’ is a string within quotes, it's considered to be true.