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

The Archive Base Latest Questions

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

-1 == true; // false -1 == false // false -1 ? true :

  • 0
-1 == true;        // false
-1 == false        // false
-1 ? true : false; // true

Can anyone explain the above output? I know I could work round this by comparing to 0 but I’m interested. I’d expect at least one of the sloppy equals statements to be true as they do implicit type conversion, and I certainly didn’t expect the ternary to come up with a totally different result.

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

    In the first two cases, the boolean is cast to a number – 1 for true and 0 for false. In the final case, it is a number that is cast to a boolean and any number except for 0 and NaN will cast to true. So your test cases are really more like this:

    -1 == 1; // false
    -1 == 0; // false
    true ? true : false; // true
    

    The same would be true of any number that isn’t 0 or 1.

    For more detail, read the ECMAScript documentation. From the 3rd edition [PDF], section 11.9.3 The Abstract Equality Comparison Algorithm:

    19. If Type(y) is Boolean, return the result of the comparison x == ToNumber(y).

    It’s worth giving the full algorithm a read because other types can cause worse gotchas.

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

Sidebar

Ask A Question

Stats

  • Questions 508k
  • Answers 508k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer As an addition to the methods described here, as Robert… May 16, 2026 at 4:19 pm
  • Editorial Team
    Editorial Team added an answer It's the TextBoxFor helper method that's responsible for generating the… May 16, 2026 at 4:19 pm
  • Editorial Team
    Editorial Team added an answer Twisted should be able to help you. Take a look… May 16, 2026 at 4:19 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

Can anyone explain why this happens? mybox:$ ruby script/console Loading development environment (Rails 2.3.5)
can anyone explain on this 2 properties Q1. hibernate.cglib.use_reflection_optimizer ? what is the effect
boolean a = false, b = true; if ( a && b ) {
Ive just had some fantastic help from Sandeepan, thank you! Please can anyone see
In this page , when you submit the form the page seems to stay
Investigating a bug, I discovered it was due to this weirdness in c#: sbyte[]
I get this behavior in both Chrome (Developer Tools) and Firefox (Firebug). Note the
I'm completely ignorant of SQL/databases, but I was chatting with a friend who does
As of Java 1.5, you can pretty much interchange Integer with int in many
I'm trying to write code that uses a member typedef of a template argument,

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.