Exclamation mark before a variable in JavaScript?

By Gulshan Saini
Published in JavaScript
December 08, 2021
1 min read

If you have ever noticed an exclamation mark (!) before the variable in someone’s JavaScript code you may be curious what it’s for and what it does.

The negation operator (!) simply just reverses the meaning of its operand. ! is the logical not operator in JavaScript.

Example of !(not) operator in JavaScript

In the below image, I am using Chrome developer tools to demonstrate this example

An exclamation mark before the variable in JavaScript
An exclamation mark before the variable in JavaScript

In the above example, we are setting the variable sleeping to false.

When we first log the value of sleeping on the console, it gives us an output of false.

However, when we negate the variable by prefixing it with an exclamation mark; !sleeping the output is changed to true.


Previous Article
Using find command to recursively look for files with a specific extension

Related Posts

JavaScript get tomorrow's date
December 13, 2021
1 min
Gulshan Saini

Gulshan Saini

Fullstack Developer



Subscribe to our newsletter!

We'll send you the best of our blog just once a month. We promise.

Quick Links

Contact UsBrowserCSSPythonPuppeteer

Social Media