Boolean Data Type & Values

Using boolean variable (true or false) in javascript?

Explanation

Boolean Data Type- E.g: true
It can have logical values true or false.
Variable type Boolean should not have any quotes.
i.e. "true" is not equal to true, "true" will be considered as a string.
var a = true;
var b = false;

Boolean variable values are mostly used along with "if", "if else" statements and "while" loops.

Example:


<script language="javascript">
var a = true;
if(a == true)
{
document.write("this is true");
}
</script>

Result:


this is true


Ask Questions

Ask Question