Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6474823
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T06:37:59+00:00 2026-05-25T06:37:59+00:00

I was playing around with arrays in Javascript today and noticed this little gem:

  • 0

I was playing around with arrays in Javascript today and noticed this little gem:

alert([1, 2, 3] == [1, 2, 3]); //alerts false

It strikes me as rather odd that the array is not equal to itself.

But then I noticed this, which was even weirder:

alert([1, 2, 3] == "1,2,3");  //alerts true

?!?!?!?!!!?

Why in the world is [1, 2, 3] not == to itself but is == to the string?

I realize that == is not the same as ===. Even so, what evilness could cause Mr. Javascript do such weird things?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T06:37:59+00:00Added an answer on May 25, 2026 at 6:37 am

    Ok, so first you need to understand how javascript treats values in your program. All of your variables that you create are going to merely be references to a location in memory where that object is stored. Therefore, when you do this:

    alert( [1,2,3] == [1,2,3] );
    

    …it does three things:

    1. Place an array ([1,2,3]) onto the heap
    2. Place another array ([1,2,3]) onto the heap (notice it will have a different memory location)
    3. Compare the two references. They point to different objects in different locations in memory, thus it is considered not equal.

    You can check for some sane behavior by running this code:

    var a = [1,2,3];
    var b = a;
    alert (a == b)   // Result is true. Both point to the same object.
    

    Now for your question about the string

    When you use the == operator tries to convert the two operands to the same type (evil behavior…I know…)

    When it does this, it decides to convert both to a string before it does the compare (thus the result is really "1,2,3" === "1,2,3", which evaluates to true.

    I can’t give you a complete picture, as there are few people who understand every nuance of the madness that is JavaScript, but hopefully this clears some of the fog.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I was playing around with this code. http://programmersvoice.com/tag/code And I noticed that the following
While playing around with regexps in Scala I wrote something like this: scala> val
After playing around with haskell a bit I stumbled over this function: Prelude Data.Maclaurin>
I'm playing around with the <canvas> element, drawing lines and such. I've noticed that
I've been playing around a little with the Exocortex implementation of the FFT, but
This is my first post, so please be gentle. I've been playing around with
I am using HTML 5 for the first time, and playing around with this
I am learning C and I am playing around with pointers and arrays. I
I was playing around with some code today, and I came across the idea
I'm currently playing around with App Widgets in Android and I'm a little confused

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.