Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

203
Views
Javascript: using "!!" in boolean context

Is there any reason to use !!someValue (which is equivalent to Boolean(someValue)) in a boolean context? In other words, in situations like if (someValue) ..., does it make sense to write if (!!someValue) ...?

It hurts my eyes and I think it's redundant, but I want to verify that there aren't any edge cases that require it - because I came across a codebase where this seems to be the default way of checking for truthiness.

Clarification: yes, in the general case !!someValue will convert someValue to a boolean; I'm referring to contexts where the runtime will automatically convert someValue to true or false.

about 4 years ago · Juan Pablo Isaza
3 answers
Answer question

0

That's a helpful way of converting any data type into boolean; The exact synonym would be:

Boolean(someValue)

Some prefer the 'double bang' as being more coincise, while others prefer the classic conversion with Boolean(someValue) for better readability.

So returning to your question, it's most likely redundant in conditions, but it can be handy when needing a conversion from any type to boolean.

about 4 years ago · Juan Pablo Isaza Report

0

Can't say I know why anyone would rely on directly checking booleans rather than on truthiness, but there is at least one scenario where truthiness is different than coercing with !!.

console.log([] == false); // true
console.log(!![] == false); // false
if([]) { console.log(true); } // true
if([] == false) { console.log(true); } // true
if(!![] == false) { console.log(true); } else { console.log(false); } // false

about 4 years ago · Juan Pablo Isaza Report

0

You never need to use a double bang to convert a boolean value to boolean.

boolean === !!boolean
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!