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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T02:09:34+00:00 2026-06-12T02:09:34+00:00

Why do the last two behave differently (tested on Google Chrome’s console)? /* number

  • 0

Why do the last two behave differently (tested on Google Chrome’s console)?

               /* number */                       /* string */
         0               == false;         ''               == false;
         !!0             == false;         !!''             == false;
         Number(0)       == false;         String('')       == false;
         !!Number(0)     == false;         !!String('')     == false;
         new Number(0)   == false;         new String('')   == false;
         (new Number(0)) == false;         (new String('')) == false;
         !!new Number(0) == true;          !!new String('') == true;

In other words, why is casting to boolean different if Number or String are called with the new keyword (While e.g., Array() and new Array() work identically)?

Also, bonus question. Why is '' == 0? I would expect that comparison to implicitly cast 0 to '0', since it would be a widening conversion, while casting both to booleans before the comparison is a narrowing conversion.

  • 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-06-12T02:09:36+00:00Added an answer on June 12, 2026 at 2:09 am
    • new Number(0) returns a Number object, which is truthy regardless of its value. Therefore, !!(true) == true.
    • Number(0) returns the number 0, which is falsey: !!(false) == false

    As for your bonus question, '' gets cast to an integer when you use the double equals sign. parseInt('') == 0.

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

Sidebar

Related Questions

I was playing with Google maps for last two days and started understanding little
I am new to programming (day 3) and I spent the last two days
I don't understand why these two examples behave differently. The objective of the HTML
Given the following code, I expect the last two lines to behave the same,
As a two-monitor user at work, I've noticed that applications behave differently with regards
I want to extract last two words of a sentence and replacing with other
In the last two days, ive run across code that has php echo'd variables
How do I remove the last two chars from each line in a text
What is the problem with the last two statements in the code? #include <iostream>
There is an example on php.net how to get last two domain segments in

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.