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 7670467
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T15:49:45+00:00 2026-05-31T15:49:45+00:00

When working within javascript can someone provide me a good reference or explanation over

  • 0

When working within javascript can someone provide me a good reference or explanation over testing for equality/inequality and type coercion?

From what I have been reading I see where there are two principles of thought on using eqeq (==) vs. eqeqeq (===) some feel that you should not use eqeq and always as use eqeqeq as it is safer to use.

I have been playing around with some basic samples and I am having trouble discerning the difference or when best to use one over the other:

For example: here is some basic script I was writing out. When I test using eqeq or eqeqeq I get the same result. I have not seen an example yet where I would get a different results (ie. using eqeq returns true where eqeqeq returns false).

function write(message){

  document.getElementById('message').innerHTML += message +'<br/>';
}


var tim = { name: "tim" };
var tim2 = { name: "tim" };
//objects are equal to themselves ( == vs ==== eqeq or eqeqeq)
write("tim eq tim: " + (tim == tim)); //returns true

//objects are only equal to themselves regardless of containing value got that
write("tim eq tim2: " + (tim === tim2)); //returns false

//access the primative type to test true or false
write("tim value eq tim2 value: " + (tim.name === tim2.name)); //returns true
//how does this differ in efficency over the eqeq operator? is one safer to use over the other?
//write("tim value eq tim2 value: " + (tim.name == tim2.name)); //also returns true

//testing primatives

write("apple eqeqeq apple: " + ("apple" === "apple"));  //true
write("apple eqeqeq apple: " + ("apple" == "apple"));  //true

Can someone provide an explanation or reference I can read that helps clarify this a bit more.

cheers,

  • 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-31T15:49:47+00:00Added an answer on May 31, 2026 at 3:49 pm

    The difference between == and === is fairly simple: == is a comparison of value. === is a comparison of value and type. Using === will prevent JavaScript from dynamically determining type and compares values exactly as they are.

    5 == "5"     //true - JS compares the number 5 to a string of "5" and determines the contents are the same 
    5 === "5"    //false - A character is not a number, they can't be the same.
    
    0 == false   //true - false is a bool, 0 is numerical, but JS determines that 0 evaluates to false
    0 === false  //false - numeric is not boolean, they can't be exactly the same thing
    
    5 == 5.0     //true - need I say more?
    5 === 5.0    //true - one is a float and one is an int, but JS treats them all as numerical
    

    I find it’s critical for tests with functions that can return both false (for failure) and 0 (as a legitimate result).

    JS has a total of 5 primitive types = numerical, string, boolean, null and undefined. === requires both arguments to be of the same type and equal value to return true. There are no float, int, long, short, etc – any type of number is lumped together as numerical.

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

Sidebar

Related Questions

Hopefully somebody can help me out here. I'm working within an embedded ActionScript2 and
How can I change the current working directory from within a Java program? Everything
I am currently working on getting JavaScript to execute successfully from within Python. I
In Javascript, we can call methods on string literals directly without enclosing it within
For some reason, I can't get rgba working within my CSS using IE9. I've
Can i use native javascript for loop within jquery code? I have a construct
I am currently working within a WPF user control (the root element of my
I am working within an intranet environment. We have both a production and development
As a developer who spent many years working within Visual C++ 6, I'm used
Is there some smart way to retreive the installation path when working within a

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.