Thursday, August 19, 2021

Logical Operators && || and ! in Javascript for Taking Decisions

Logical Operator : In Javascript for making decision in our code we use Logical Operators like - && (And), || (OR) !(Not)

// Anil has driver's licence.
// Anil has good vision.

// And , OR !
const hasDtiverLicence = true;
const hasGoodVision = true;
const isTired = false;


/ * console.log(hasDtiverLicence && hasGoodVision);
console.log(hasDtiverLicence || hasGoodVision);
console.log(!hasDtiverLicence); */

if (hasDtiverLicence && hasGoodVision) {
console.log(`Anil is able to drive`);
} else {
console.log(`Someone else Drive`);
}

if (hasDtiverLicence && hasGoodVision && !isTired) {
console.log(`Anil Can Drive a Car`);
} else {
console.log(`Someone else should Drive car`);
}

0 comments

Post a Comment