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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T07:33:07+00:00 2026-06-13T07:33:07+00:00

If a value must be defined to true or false, based off the check

  • 0

If a value must be defined to true or false, based off the check off another value, are there any gotchas in doing :

!!someValue

Just a quick run against chrome’s engine gives:

boolCheck=function(someValue){
    return !! someValue;
}

console.log(boolCheck());           //false
console.log(boolCheck(undefined));  //false
console.log(boolCheck(null));       //false
console.log(boolCheck(1));          //true
console.log(boolCheck({va:1}));     //true
console.log(boolCheck("someTS"));   //true
console.log(boolCheck(boolCheck));  //true    

which SEEMS to work….

  • 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-13T07:33:08+00:00Added an answer on June 13, 2026 at 7:33 am

    The ! operator always returns either true or false, so assuming evaluation of x completes normally, !!x is a boolean value that is the equivalent of Boolean(x) where Boolean is the EcmaScript builtin function.

    http://es5.github.com/#x11.4.9 says

    11.4.9 Logical NOT Operator ( ! )

    The production UnaryExpression : ! UnaryExpression is evaluated as follows:

    1. Let expr be the result of evaluating UnaryExpression.
    2. Let oldValue be ToBoolean(GetValue(expr)).
    3. If oldValue is true, return false.
    4. Return true.

    http://es5.github.com/#x9.2 explains how ToBoolean works

    9.2 ToBoolean

    The abstract operation ToBoolean converts its argument to a value of type Boolean according to Table 11:

    Table 11 — ToBoolean Conversions

    Argument Type    Result 
    Undefined        false
    Null             false
    Boolean          The result equals the input argument (no conversion).
    Number           The result is false if the argument is +0, −0, or NaN; otherwise the result is true.
    String           The result is false if the argument is the empty String (its length is zero); otherwise the result is true.
    Object           true
    

    The above table explains most of your examples, but it may not be obvious why

     console.log(boolCheck());
    

    is false. When you call a function with fewer actual arguments than formal parameters, the extra parameters have the value undefined and, as the table above shows !!undefined is false.


    are there any gotchas in doing : !!someValue?

    The intent is less clear than Boolean(someValue), but it will work consistently across platforms and most experienced Javascript devs will recognize it.

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

Sidebar

Related Questions

In Delphi 2009 or later (Unicode), are there any built-in functions or small routines
I'm trying to check if a variable has been defined as a nullable Guid.
I am writing a function as follows: bool abc::GetLoggingStatus() { //true or false is
I have to generate a xml element that can have as value any primitive
I must be doing something wrong here but I can't find an easy way
Update : I just stumbled upon this in Eric Lippert's answer to another question
There is a table Item like, code,name 01,parent1 02,parent2 0101,child11 0102,child12 0201,child21 0202,child22 Create
I am attempting to convert the return value of the function boost::asio::async_read to an
I have a style defined for my ListBoxItems with a trigger to set a
Im trying to change a property value (using reflection) that matches with the column

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.