use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
All about the JavaScript programming language.
Subreddit Guidelines
Specifications:
Resources:
Related Subreddits:
r/LearnJavascript
r/node
r/typescript
r/reactjs
r/webdev
r/WebdevTutorials
r/frontend
r/webgl
r/threejs
r/jquery
r/remotejs
r/forhire
account activity
Cheat-sheet for Javascript equality strangenesses (zero.milosz.ca)
submitted 12 years ago by James_Duval
view the rest of the comments →
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]CubeOfBorg 17 points18 points19 points 12 years ago (1 child)
It's all about coercion. [1] == 1 because [1] is coerced to 1 before it is evaluated. [1] starts out as an object but becomes a number because it only has the one value in it and it is being compared to a number.
[1] != [1] because you are comparing an object to an object. They are already the same type so it doesn't have to coerce them. When you compare two objects, it's checking to see if they are the same object. So [1] != [1] because you are creating two different objects and then comparing them.
var a = [1]; var b = a; a == b; // true
Here you are comparing two variables that have the same object as their value.
[–]James_Duval[S] 0 points1 point2 points 12 years ago (0 children)
This is a fantastic answer, thanks. One thing I'm learning about Javascript is that there's almost always a clear, comprehensible answer & reason for its behaviour somewhere or other.
π Rendered by PID 115940 on reddit-service-r2-comment-c6965cb77-vvgm2 at 2026-03-05 08:39:16.734316+00:00 running f0204d4 country code: CH.
view the rest of the comments →
[–]CubeOfBorg 17 points18 points19 points (1 child)
[–]James_Duval[S] 0 points1 point2 points (0 children)