How can I distinguish 0 and empty string in javascript? - Stack Overflow

Saya=""; empty Stringb=0;thena==b; returns trueWhat Test could I build to return tru

Say

a="";  // empty String
b=0;

then

a==b;  // returns true

What Test could I build to return true only if I pare two empty strings or two zero's?

Say

a="";  // empty String
b=0;

then

a==b;  // returns true

What Test could I build to return true only if I pare two empty strings or two zero's?

Share Improve this question asked Jan 28, 2015 at 22:18 Bob SBob S 2952 silver badges12 bronze badges 2
  • 1 here is a really good post of == vs. === stackoverflow./questions/523643/… – taesu Commented Jan 28, 2015 at 22:20
  • possible duplicate of Does it matter which equals operator (== vs ===) I use in JavaScript parisons? – Alexis King Commented Jan 28, 2015 at 22:21
Add a ment  | 

2 Answers 2

Reset to default 8

Use the strict parison operator, ===. This will not use JavaScript's default type coercion, so you will get the correct result.

"" === 0; // false

use === instead of == for checking undifined and zero or false pare

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745383195a4625325.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信