简体   繁体   中英

if test in javascript for boolean value

I have a boolean variable which passes the if test even if its value is false.

Here is the code:

var go = (4 > 8);
if(go) {
    //do something
}

The //do something is always executing even if the value of go is false . I tested if(go == true) and if(go === true) as well but in all these cases it passes the test and //do something gets executed.

What am I doing wrong here?

The code above is in an else if block but that should not matter.

Could someone help me understand what am I doing wrong here? I've gone nuts trying to figure out why is it happening.

there is nothing wrong with the code

just try this

say you web url is http://localtest/test.php

try appending http://localtest/test.php?test=something

this may load your js again and not pick up the cached version Edit: you are better off clearing your browser cache

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM