Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
Relational operator
(section)
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
===Comparing values of different types=== In [[JavaScript]], [[PHP]], [[VBScript]] and a few other [[Type system#DYNAMIC|dynamically typed]] languages, the standard equality operator follows so-called ''loose typing'', that is it evaluates to ''true'' even if two values are not equal and are of incompatible types, but can be ''coerced'' to each other by some set of language-specific rules, making the number 4 compare equal to the text string "4", for instance. Although such behaviour is typically meant to make the language easier, it can lead to surprising and difficult to predict consequences that many programmers are unaware of. For example, JavaScript's loose equality rules can cause equality to be intransitive (i.e., <code>a == b</code> and <code>b == c</code>, but <code>a != c</code>), or make certain values be equal to their own negation.<ref>{{cite web |last1=Denys |first1=Dovhan |title=WTFJS |website=[[GitHub]] |url=https://github.com/denysdovhan/wtfjs#-is-equal- |access-date=25 July 2024}}</ref> A strict equality operator is also often available in those languages, returning true only for values with identical or equivalent types (in PHP, <code>4 === "4"</code> is false although <code>4 == "4"</code> is true).<ref>{{cite web|url=http://www.php.net/manual/en/language.oop5.object-comparison.php |title=Comparing Objects |work=PHP Manual |publisher=PHP Group |access-date=June 29, 2014 }}</ref><ref name="php">{{cite web|url=http://php.net/manual/en/language.operators.comparison.php |title=PHP: Comparison Operators - Manual|access-date=July 31, 2008}}</ref> For languages where the number 0 may be interpreted as ''false'', this operator may simplify things such as checking for zero (as <code>x == 0</code> would be true for x being either 0 or "0" using the type agnostic equality operator).
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)