if statement always return true even for simple integer values

[亡魂溺海] 提交于 2021-02-16 18:51:49

问题


i facing issue my If statement returning always true, for each value.

 var radioValue = parseInt($("input[name=packageRadio]:checked").val())
            alert(radioValue); // 1000, 500, -1



            if ((radioValue) == -1);
            {
                alert("no");

            }

for every value alert("no") is always calling.


回答1:


Remove semicolon after if

if ((radioValue) == -1){
   alert("no");

}



回答2:


Remove semicolon ; after if.And also remove braces () rounded around radioValue. Like following

if (radioValue == -1){
   alert("no");

}



回答3:


When JavaScript parsing, semicolon means the end of the statement (or line). By that code you separate if statement and it's body.



来源:https://stackoverflow.com/questions/61556125/if-statement-always-return-true-even-for-simple-integer-values

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!