Return to Kroll Design home page

JavaScript Tutorials

 
« Return

logical operators

and: &&
both parts must be true for the expression to be true

or: ||
at least one part must be true for the expression to be true

exclusive or: ^
exactly one part must be true for the expression to be true

logical negation ("not"): !
makes the result of the expression the opposite of what it would have been

Code:

<script type="text/javascript">
//<![CDATA[
is_true = true;
is_also_true = true;
is_false = false;
is_also_false = false;
document.write("is_true && is_false : ", is_true && is_false, "<br />");
document.write("is_true && is_also_true : ", is_true && is_also_true, "<br />");
document.write("is_true || is_false : ", is_true || is_false, "<br />");
document.write("!(is_true || is_false) : ", !(is_true || is_false), "<br />");
document.write("is_true || is_also_true : ", is_true || is_also_true, "<br />");
document.write("is_true && !is_false : ", is_true && !is_false, "<br />");
//]]>
</script>

Output:



 
« Return


©2012 Kroll Design    info@KrollDesign.net    781.910.3694
Last modified: 12/31/1969 7:00 PM