views:

168

answers:

5

I'm aware of the === operator in PHP which connotes not only value equality, but type matching also i.e.

if (20 === "20") //false

Is there something similar in javascript if I'm using jquery? Examples code could help too.

Thanks

+9  A: 

Yes, it is part of the JavaScript language. === and == are the same except that == will try to convert the types while === will not.

Matt Moriarity
+3  A: 

The JavaScript behavior of === is very similar to php - check for equality and same type.
This is not jQuery by the way - jQuery is a JavaScript framework. Basically, it's a group for JavaScript functions. It isn't the language.

Kobi
+16  A: 

Yes the operator exists in javascript. jQuery is just a framework built with javascript so all of the javascript syntax and operators are still there.

tvanfosson
+4  A: 

JQuery is a Javascript library. The "==" operator does indeed exist in Javascript. If you want strict equality, you should use the "===" operator.

http://www.webreference.com/js/column26/stricteq.html

BobbyShaftoe
+2  A: 

According to an article on Net Tuts by jeffrey way titled "24 JavaScript Best Practices" that recommends:

"JavaScript utilizes two different kinds of equality operators: === | !== and == | != It is considered best practice to always use the former set when comparing."

Obviously the same rule applies when using jQuery.

see the article here: 24 JavaScript Best Practices

adardesign