Skip to content

JavaScript if not | Example code

  • by

JavaScript if not used with non-Boolean values, it returns false if its single operand can be converted to true.

Use the Logical NOT ! operator:


JavaScript if not an example

simple example code.

<!DOCTYPE html>

    var isDay = false;
    if (!isDay) { 
      console.log("It's night");


JavaScript if not

How to check if a variable is not null?

Answer: Here is how you can test if a variable is not NULL:

if (myVar !== null) {...}

the block will be executed if myVar is not null.. it will be executed if myVar is undefined or false or 0 or NaN or anything else.

Read more: JavaScript isNull

Do comment if you have any doubts or suggestions on this JS if topic.

Note: The All JS Examples codes are tested on the Firefox browser and the Chrome browser.

OS: Windows 10

Code: HTML 5 Version


Leave a Reply

Discover more from Tutorial

Subscribe now to keep reading and get access to the full archive.

Continue reading