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

  • Home
  • SEARCH
  • 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 6555001
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T12:46:00+00:00 2026-05-25T12:46:00+00:00

alert (0 == ”); // true alert (0 == ‘0’); // true JSFiddle Proof

  • 0
alert (0 == ''); // true
alert (0 == '0'); // true

JSFiddle Proof

I understand that == in javascript performs a conversion and then checks for equality, but how does it perform the conversion in the statements above? Does it convert 0 to ” or ” to 0? Or something else perhaps? Is there a spec somewhere that explains the implementation?

  • 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-25T12:46:01+00:00Added an answer on May 25, 2026 at 12:46 pm

    It uses the Abstract Equality Comparison Algorithm.

    Specifically for your example

    If Type(x) is Number and Type(y) is String,
    return the result of the comparison x == ToNumber(y).

    So then you’ll end up with:

    0 == 0
    

    …in both cases because an empty string converts to the number 0, and a numeric string converts to the number given.

    From 9.3.1 ToNumber Applied to the String Type:

    A StringNumericLiteral that is empty or contains only white space is converted to +0

    Since we’re now doing a comparison of the same Type on the second pass, it will do the following:

    If Type(x) is the same as Type(y), then

    …
    If Type(x) is Number, then

    …
    If x is the same Number value as y, return true.


    To test a toNumber conversion, you can use the unary + operator.

    console.log( +'' );   // 0
    console.log( +'0' );  // 0
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an alert dialog, that I have 2 text fields and then a
I have an alert script that I am trying to keep from spamming me
Newbie alert! OK, I have a working central Mercurial repository that I've been working
NEWBIE ALERT! background: For the first time, I am writing a model that needs
In javascript alert(document.cookie); does not show the .ASPXAUTH Cookie although a sniffer is showing
****C newbie alert**** How do I compile a C app so that it runs
For a standard Javascript alert() box, is it possible to have it appear in
alert(Date.parse('Mar 1 1990')); in jsFiddle, this returns a datetime integer, as expected. On my
Via alert I have the information string 1:CX.PC.PB.0012.S.S which is from alert(c_itemvalue); Then I
Newbie alert... I'm trying to make an educational that uses different audio players (with

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.