what does "===" imply in Javascript/Jquery?

Possible Duplicate:
JavaScript === vs == : Does it matter which “equal” operator I use?
The 3 different equals

I'm trying to understand what is happening here:

 data.toPage = $('div#someID');

if ( typeof data.toPage === "string" ) {
      // sth
      console.log("hello");
      }

So I'm checking for a string am I not? I'm curious because my console "helloes".

Thanks for some input!


== This is the equal operator and returns a boolean true if both the operands are equal. JavaScript will attempt to convert different data types to the same type in order to make the comparison. Assuming 'a' to be 2 and 'b' to be 4, the following examples will return a value of true:

a == 2
a == "2"
2 == '2' 

=== This is the strict equal operator and only returns a Boolean true if both the operands are equal and of the same type. These next examples return true:

a === 2
b === 4 

===比较运算符意味着这两个值在进行比较之前不会修改它们的类型,所以它们需要具有相同的类型以及表示相同的值才能返回true。

'1' == 1 // true
'1' === 1 // false

The triple equals sign === compares both value and type, whereas the double == only compares value

for example "1" and 1 have the same value (so to speak) but are of different types. Therefore the following will occur:

"1" == 1 //true
"1" === 1 //false

This is a great read for some useful javascript knowledge, which includes the triple equals amongst other good-to-know stuff

链接地址: http://www.djcxy.com/p/58458.html

上一篇: 当进行==和===比较时,变量的顺序是否重要?

下一篇: JavaScript / Jquery中“===”的含义是什么?