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.

Revisions

  1. raghu-icecraft created this gist May 23, 2019.
    35 changes: 35 additions & 0 deletions JavaScript_TryItWith{}Comparision.html
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,35 @@
    <!-- 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>