Check if Multiple Variables are Not NULL in JavaScript-Code Examples

Radu TM

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

18.864

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

18.864

Check if Multiple Variables are Not NULL in JavaScript

JavaScript by Radu TM June 21, 2022

if (!(x === null && y === null && z === null)) {
  // at least one variable is not null
}

0

18.864

Related JavaScript Queries

Latest JavaScript Queries

Explore code examples by categories