JavaScript Common Mistakes
JavaScript programs may generate unexpected results if a programmer accidentally uses an assignment operator (
<p id="demo"></p>
<script>
var x = 0;
document.getElementById("demo").innerHTML = Boolean(x == 8);
</script>
This
=
), instead of a comparison operator (==
) in an if statement.<p id="demo"></p>
<script>
var x = 0;
document.getElementById("demo").innerHTML = Boolean(x == 8);
</script>
This
if
statement returns false
(as expected) because x is not equal to 8:
Комментарии
Отправить комментарий