Note: A variable or object which has a value is treated as a true boolean value. ‘0’, ‘NaN’, empty string, ‘undefined’, and ‘null’ is treated as false boolean values.
Here a1 and a2 store 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";
Example 1: 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
Example 3: 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: v1 = = = v2 is not true as the type of v1 and v2(object) is not the same.
- Google Chrome 6 and above
- Edge 12 and above
- Firefox 4 and above
- Internet Explorer 9 and above
- Opera 12 and above
- Safari 5.1 and above