Skip to content

What does the double negation operator !! do in JavaScript?

New Course Coming Soon:

Get Really Good at Git

You might find the `!!` operator used in the wild. What does it mean?

Suppose you have an expression, which gives you a result.

You want this result to be a boolean. Either true or false.

Not a string, 0, an empty string, undefined, NaN or whatever. true or false.

The !! operator does that.

And in reality it’s two negation operators one after the other. There’s no !! operator in JavaScript. But there’s !.

It first negates the result of the expression, then it negates it again. In this way if you had a non-zero number, a string, an object, an array, or anything that’s truthy, you’ll get true back.

Otherwise you’ll get false.

Are you intimidated by Git? Can’t figure out merge vs rebase? Are you afraid of screwing up something any time you have to do something in Git? Do you rely on ChatGPT or random people’s answer on StackOverflow to fix your problems? Your coworkers are tired of explaining Git to you all the time? Git is something we all need to use, but few of us really master it. I created this course to improve your Git (and GitHub) knowledge at a radical level. A course that helps you feel less frustrated with Git. Launching Summer 2024. Join the waiting list!
→ Get my JavaScript Beginner's Handbook
→ Read my JavaScript Tutorials on The Valley of Code
→ Read my TypeScript Tutorial on The Valley of Code

Here is how can I help you: