Example of boolean values:
Here a1 and a2 stores the boolean value i.e. true and false respectively.
var a1 = true; var a2 = false;
Note: Below variables are initialized with strings not boolean values.
var a1 ="true"; var a2 ="false";
Note: A variable or object which has value are treated as true boolean values. ‘0’, ‘NaN’, empty string, ‘undefined’, ‘null’ are treated as false boolean values.
Below program will give true values as output.
Boolean(10) is true Boolean("GeeksforGeeks") is true Boolean(2.74) is true Boolean(-1) is true Boolean('true') is true Boolean('false') is true Boolean(3 * 2 + 1.11) is true Boolean(1<2) is true
Below program will give false values as output.
Boolean(0) is false Boolean("") is false Boolean(e) undefined is false Boolean(-0) is false Boolean(false) is false Boolean(NaN) is false Boolean(null) is false Boolean(1>2) is false
v1 = false v2 = false v3 = false v4 = false v5 = true v6 = true
v1 = = v2 is true v1 = = = v2 is false
Note: note that v1 = = = v2 is not true as the type of v1 and v2(object) is not same.
- How to convert string to boolean in PHP?
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.