6. Operators Flashcards
Equality Operators, Loose Operator , Strict Operator, Logical Operator
Symbol for Equality Operator ?
=== (is an strict equality operator)
Example for Strict Operator (Reveal Answer )
let age = 18 if (age === 18) console.log('You have become an adult');
In the above example using the if statement ( if we get the exact value then it will show the output in the console else it will not show anything);
Symbol for Loose Operator ?
== (is an loose operator)
Example for Loose Operator (Reveal Answer )
let kiranage = '18' if (kiranage == 18) console.log("I understood the concept");
Here in the above example now since == is a loose operator it will convert string to a number and will match and will show the output.
Which Operator can convert any string or values ?
== (loose operator) (can convert any string or values)
Which operator matches the exact value without which the code will not be executed ?
=== (strict operator)
Symbol for AND Operator ?
&&
Symbol fro NOT Operator
||
Symbol for NOT Operator
!
Example for AND Operator
Reveal Answer
const hasDriversLicense = true //A const hasGoodVision = true //B
console.log(hasDriversLicense && hasGoodVision)
Because ( true + true = True ) as per the Boolean logic table.
Example 2 const hasDriversLicense = true //A const hasGoodVision = false //B
console.log(hasDriversLicense && hasGoodVision);
Output = false
Explanation :- true + false = false ( if any one is false then it will be false )
Example for OR Operator (||)
Reveal Answer
const hasDriversLicense = true //A const hasGoodVision = false //B
console.log(hasDriversLicense || hasGoodVision);
Output :- true
Example of NOT OPERATOR (!)
Reveal Answer
const hasDriversLicense = true //A const hasGoodVision = false //B
console.log(!hasDriversLicense);
Explanation :- true + false = false ( if any one is false then it will be false )