admin管理员组文章数量:1425161
In the plain javascript function. Both the values, min_chk and max_chk are true, but the if function still shows the alert. not able to figure why?
function Checkit(m,n){
return m>n;
}
var min_chk = Checkit(a,X);
var max_chk = Checkit(b,Y);
if ((min_chk === 'true') && (max_chk === 'true')){
...
} else {
alert('invalid range');
}
In the plain javascript function. Both the values, min_chk and max_chk are true, but the if function still shows the alert. not able to figure why?
function Checkit(m,n){
return m>n;
}
var min_chk = Checkit(a,X);
var max_chk = Checkit(b,Y);
if ((min_chk === 'true') && (max_chk === 'true')){
...
} else {
alert('invalid range');
}
Share
Improve this question
asked Jan 15, 2013 at 22:47
RajeevRajeev
1,4237 gold badges31 silver badges48 bronze badges
0
3 Answers
Reset to default 3The ===
operator returns false
if the operands on both sides have different types. The boolean true
and the string "true"
have different types.
You should change your check just to
if (min_chk && max_chk)
Since min_chk
and max_chk
are already booleans, you don't need to pare them directly with true
.
The boolean true
is not the same as the string 'true'
. Remove the quotes.
Get rid of the '' around true
function Checkit(m, n) {
return m > n;
}
var min_chk = Checkit(a, X);
var max_chk = Checkit(b, Y);
if ((min_chk === true) && (max_chk === true)) {...
} else {
alert('invalid range');
}
本文标签: javascript true and true returning false in if statementStack Overflow
版权声明:本文标题:javascript true and true returning false in if statement? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745415946a2657685.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论