Javascript BigInt Conditional Operation

Introduction

A BigInt behaves like a Number where:

  • converted to a Boolean via the Boolean function;
  • used with logical operators ||, &&, and !;
  • within a conditional test like an if statement;
if (0n) {/* w  w w .  j  av  a 2  s. c o m*/
  console.log('if!')
} else {
  console.log('else!')
}
console.log(0n || 12n);
console.log(0n && 12n);
console.log(Boolean(0n));
console.log(Boolean(12n));
console.log(!12n);
console.log(!0n);



PreviousNext

Related