/

HTML / CSS / JavaScript Tutorial

JavaScript Operator: logical NOT

[this page | pdf | back links]

In JavaScript, the ! operator is the logical (i.e. Boolean) NOT operator:

 

x

!x

true

false

false

true

 

EXAMPLE:


HTML USED IN THIS EXAMPLE:
<!DOCTYPE html>
<html> <!-- Copyright (c) Nematrian Limited 2018 -->
<head>
<style>table,th,tr,td {border: 1px solid black;
  border-collapse: collapse;}</style>
</head>
<body>
<table>
<tr>
<th>x</th><th>!x</th>
</tr>
<tr>
<td><code>true</code></td><td><code id="TrueX"></code></td>
</tr>
<tr>
<td><code>false</code></td><td><code id="FalseX"></code></td>
</tr>
<tr>
</table>

<script>
document.getElementById("TrueX").innerHTML = ! true;
document.getElementById("FalseX").innerHTML = ! false;
</script>

</body>
</html>


NAVIGATION LINKS
Contents | Prev | Next | JavaScript Operators


Desktop view | Switch to Mobile