Why does != work and just = doesn't?

后端 未结 6 412
陌清茗
陌清茗 2021-01-29 15:41

Here\'s my code:

  if (document.getElementById(\"hiddenButton\").style.visibility != \"visible\") {
     document.getElementById(\"hiddenButton\").style.visibili         


        
6条回答
  •  旧时难觅i
    2021-01-29 16:37

    JS Comparison operators

    ==      is equal to 
    ===     is exactly equal to (value and type)
    !=      is not equal
    

    For example:

    var x = 1;  //define and assigned and now x equal to 1
    x = 3;        //now x equal to 3
    
    if( x == 4) {
        //you won't see this alert
        alert('Hello, x is 4 now');
    } else {
        //you will see this alert
        alert('Hello, x hasn not been changed and it is still ' + x.toString());
    }
    

提交回复
热议问题