Check if a Variable is Not NULL in JavaScript-Code Examples

Radu TM

Check if a Variable is Not NULL in JavaScript

JavaScript by Radu TM June 21, 2022

// check if variable is not null
if (variable !== null) {
  // do something
}

0

14.343

Check if a Variable is Not NULL in JavaScript

JavaScript by Radu TM June 21, 2022

if (variable !== null) {
  // do something
}

0

14.343

Check if Multiple Variables are Not NULL in JavaScript

JavaScript by Radu TM June 21, 2022

let a = "not null";
let b = "also not null";

// we can check if multiple variables are not null in JavaScript like this
if(a !== null && b !== null) {
  // if both variables are not null, this code will run
  console.log(" both a and b are not null");
} else {
  // if one or both variables are null, this code will run
  console.log(" one or both of a and b are null");
}

0

13.403

Check if Multiple Variables are Not NULL in JavaScript

JavaScript by Radu TM June 21, 2022

let a = 1;
let b = 2;
let c = 3;

if (a !== null && b !== null && c !== null) {
  console.log("All variables are not null!");
} else {
  console.log("One or more variables are null!");
}

0

13.403

Related JavaScript Queries

Latest JavaScript Queries

Explore code examples by categories