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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T08:26:15+00:00 2026-06-04T08:26:15+00:00

I am now confused about ! operator in JavaScript. My understanding was ! operator

  • 0

I am now confused about ! operator in JavaScript. My understanding was ! operator operates only on boolean. But a comment to one of my answers says it can operate on anything and returns a boolean, which happened to be true after I did some tests.

alert(!undefined); //true
alert(!function(){}); //false
alert(!{}); //false
alert(!null); //true
alert(!()); //crash
alert(!"false"); //false
alert(!false)​;​​​​​​​​​​​​ //true​​​​​​​​​​​​​​​​​​

Can somebody help me generalize the behavior of ! operator.

EDIT

Even more confusing stuff:

​alert( new String() == ""); //true
alert(!""); //true
alert(! new String()); //false

How?
​

  • 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-04T08:26:16+00:00Added an answer on June 4, 2026 at 8:26 am

    ! does what you think: turns true to false and vice-versa. The weird behavior has to do with how Javascript can convert literally anything to true or false.

    http://11heavens.com/falsy-and-truthy-in-javascript

    Like in C (only worse) all values can be promoted to true or false. The googlable terms you want are “truthy” and “falsy,” or “truthiness” and “falsiness.” Truthy means something converts to true, falsy means something converts to false. All values are truthy except null, undefined, 0, "", NaN, and… false

    This link has more fun examples:

    http://www.sitepoint.com/javascript-truthy-falsy/

    And this site really likes doing pathological things with the funny behavior here:

    http://wtfjs.com

    Also note that == really tries hard to make things comparable whereas === just returns false if the things aren’t comparable. Crockford in Javascript: The Good Parts recommends not using == entirely.

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

Sidebar

Related Questions

Ok, I'm now very confused. After my last question had several people comment about
It might look silly, but I'm kind of confused about this now. Why this
I'm confused about the problem and not sure if I can provide enough details.
I'm a little confused about how the standard library will behave now that Python
I am confused about js file of jQuery which one i have downloaded just
I'm losing it here.. I am now extremely confused about how this loop works.
I work for a php user authorization class and now I’m confused about sessions
I've been staring at this for a while now and I'm confused about what
I've been reading about OrientDB for a while now, and I'm a bit confused
i'm confused about assocation table naming (for many to many asscoation) now i have

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.