Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save raghu-icecraft/3ac72892ce9d19ee1d7b449dd965addd to your computer and use it in GitHub Desktop.
Save raghu-icecraft/3ac72892ce9d19ee1d7b449dd965addd to your computer and use it in GitHub Desktop.
Java script check on comparision with {}
<!-- Comment
1. {} == 3 or {} === 3 comparision when tried in any modern browser console yields in error
And the same comparision when done using if block works well and goes to else part of the code.
2. Further, use the below html file to understand the comparision like in Runtime.
Sample output:
display x:
21
Code is edited after initial reference from https://www.w3schools.com/jsref/tryit.asp?filename=tryjsref_oper_add
-->
<!DOCTYPE html>
<html>
<body onload="myFunction()">
<p>Display x:</p>
<p id="demo"></p>
<script>
function myFunction() {
var x = 0;
if ({} == 3) {
x = 5;
} else {
x = 21;
}
document.getElementById("demo").innerHTML = x;
console.log("hello");
}
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment