In JavaScript is != same as !==

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

Look at this commit

Is != same as !== in JavaScript?

[1]:


They are subtly not the same.

!= checks the value
!== checks the value and type

'1' != 1   // false (these two are the same)
'1' !== 1 // true (these two are **not** the same).

In the previous example. The first half of the expression is a string, the second half is an integer.


From

http://en.wikipedia.org/wiki/JavaScript_syntax#Operators

!== Not identical

!= Not equal

AND "Identical means equal and of same type."

From

http://docstore.mik.ua/orelly/webprog/jscript/ch05_04.htm

"In JavaScript, numbers, strings, and boolean values are compared by value. ... On the other hand, objects, arrays, and functions are compared by reference. "

--

So in summary are they the same? No, because there is an additional test with !== (over !=) for type sameness as well as equalness.


No, it is not the same. See for example here.

4 !== '4' returns true   (and 4 === '4' returns false)
4 != '4'  returns false  (and 4 == '4'  returns true)
链接地址: http://www.djcxy.com/p/3242.html

上一篇: 三(3)等号

下一篇: 在JavaScript中!=和!==相同