Created
May 23, 2019 19:40
-
-
Save raghu-icecraft/3ac72892ce9d19ee1d7b449dd965addd to your computer and use it in GitHub Desktop.
Java script check on comparision with {}
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <!-- 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