To find the Boolean value of something, you can use the Boolean function like so:
Boolean(“hello”);
<< true
Boolean(42);
<< true
Boolean(0);
<< false
<< true
Boolean(42);
<< true
Boolean(0);
<< false
Only seven values are always false and these are known as falsy values:
* "" // double quoted empty string
* '' // single quoted empty string
* 0
* NaN
* false
* null
* undefined
* '' // single quoted empty string
* 0
* NaN
* false
* null
* undefined
Truthy and Falsy Values
The fact that empty strings and zero are considered falsy can cause confusion at times, especially since other programming languages don't behave similarly. A ninja needs to be especially careful when dealing with numbers that might be zero, or strings that are empty.For more on truthy and falsy values, see this article on SitePoint
0 Response to "Booleans"
Post a Comment