JavaScript Operator: strictly equal
[this page | pdf | back links]
In JavaScript,
the === operator is
the ‘strictly equal to’ operator:
x
|
y
|
x == y
|
8
|
"8"
|
false
|
8
|
8
|
true
|
Note: if x and y
are of the same type then this operator should return the same as the ‘equal to’
operator, ==.
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; text-align: center;}</style>
</head>
<body>
<table>
<tr>
<th> x </th><th> y </th>
<th><code>x == y</code></th><th><code>x === y</code></th>
</tr>
<tr>
<td><code>8</code></td><td><code>"8"</code></td>
<td><code id="A1"></code></td><td><code id="A2"></code></td>
</tr>
<tr>
<td><code>8</code></td><td><code>8</code></td>
<td><code id="B1"></code></td><td><code id="B2"></code></td>
</tr>
<tr>
</table>
<script>
document.getElementById("A1").innerHTML = 8 == "8";
document.getElementById("A2").innerHTML = 8 === "8";
document.getElementById("B1").innerHTML = 8 == 8;
document.getElementById("B2").innerHTML = 8 === 8;
</script>
</body>
</html>
|
NAVIGATION LINKS
Contents | Prev | Next | JavaScript Operators