开发者

Difference between == and === in JS [duplicate]

开发者 https://www.devze.com 2023-02-17 07:20 出处:网络
This question already has answers here: Closed 11 years ago. Possibl开发者_如何学JAVAe Duplicates:
This question already has answers here: Closed 11 years ago.

Possibl开发者_如何学JAVAe Duplicates:

Difference between == and === in JavaScript

Javascript === vs == : Does it matter which “equal” operator I use?

What's the difference between == and ===? Also between !== and !==?


There are lots of answers to this question on Stackoverflow already.

Short:

== only compares values

=== compares values + type


var check1 = '10',
    check2 = 10;

check1 == check2 // true
check1 === check2 // false


"==" means equals, whereas "===" means identically equal.

In short, "==" will try and coerce/convert the types of values when doing a comparison, so "2"==2, whereas "===" will not.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号