Learn JavaScript the Eloquent Way- Operators

Subscribe to my newsletter and never miss my upcoming articles

🏳️‍🌈 Arithmatic Operators

let x = 10;
let y = 3;

console.log(x + y);
// 13

console.log(x - y);
// 7

console.log(x * y);
// 30

console.log(x/y);
// 3.3333

console.log(x % y);
// 1

console.log(x ** y);
// 1000

🏳️‍🌈 Assignment Operators

let x = 10;

x = x + 5;
// Above statement is equal to
x += 5;
console.log(x);
// 15

🏳️‍🌈 Comparision Operators

let x = 1;

console.log(x > 0);
// true

console.log(x >= 1);
// true

console.log(x < 1);
// false

// Equality Operators
console.log(x === 1);
// true

console.log(x !== 1);
// false

🏳️‍🌈 Equality Operators

// Strict Equality operator

console.log(1 === 1);
// true

console.log(1 === '1');
// false


// Lose Equality operator

console.log(1 == 1 );
// true 

console.log(1 == '1');
// true

🏳️‍🌈 Ternary Operators

// We will understand Ternary Operator with an example

// if a customer have more  
// than 100 points they are 
// gold otherwise they are silver

let points = 110;
let type = points > 100 ? 'gold' : 'silver';

console.log(type);
// gold

Alt Text

🏳️‍🌈 Logical Operators

// There are Three Types Of Logical Operators

// Logical and

console.log(true && true);
// true

console.log(true && false);
// false

// Logical OR

console.log(true || true);
// true 

console.log(true || false);
//true

//Logical NOT

console.log(!true);
// false

console.log(!false);
// true


// Falsy and Truthy Values

// Falsy values
// undefined,null,0,false,'',NaN


//Truthy values
// all Other are Truthy values

🏳️‍🌈 Bitwise Operators

Alt Text

// Bitwise  OR
// It compares individual values of Binary values and retuns individual
// Bitwise OR
console.log(1 | 2);
// 3

Alt Text

// Bitwise AND
console.log(1 & 2);

Alt Text

No Comments Yet