Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
183 views
in Technique[技术] by (71.8m points)

Why is tab equal to false in JavaScript?


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

See Abstract Equality Comparison::

The comparison x == y, where x and y are values, produces true or false. Such a comparison is performed as follows:

So, in your situation, x is a string, and y is a boolean. The first condition that is fulfilled here is:

  1. If Type(y) is Boolean, return the result of the comparison x == ToNumber(y).

Turning the check into

'' == 0

Which then fulfills:

  1. If Type(x) is String and Type(y) is Number, return the result of the comparison ToNumber(x) == y.

And ToNumber('') === 0:

console.log(Number(''));

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...