Topic 8: Operators: arithmetic & comparison operators

//Revision Lecture 11: 7 Oct 2022

//Topic 8: //* operators *// arithmetic & comparison operators//

//A) arithmetic operators
//B) comparison operators
//C) logical operators
//D) ternary operator
//E) typeof operator
//---------------------------

//A) arithmetic operators:
//+, -, *, /, %, ++, --, **

//1) addition operator + : do addition

let a = 10; b = 20;
console.log(a+b)
//output--> 30

let a1 = 15; b1 = 22
console.log(a1+b1)
//output--> 37


//2) subtraction operator - : do subtraction

console.log(b-a)
//output--> 10

console.log(b1-a1)
//output--> 7


//3) multiplication operator * : do multiplication

console.log(a*b)
//output--> 200

console.log(a1*b1)
//output--> 330


//4) division operator / : do multiplication

console.log(b/a)
//output--> 2

console.log(b1/a1)
//output--> 1.46


//5) modulus/remainder operator % : returns remainder after division

console.log(b%a)
//output--> 0

console.log(50%4)
//output--> 2


//6) increment operator ++ : increases value by 1

let a2 = 5
console.log(++a2)
//output--> 6

let a3 = 7
console.log(++a3)
//output--> 8


//7) decrement operator -- : decreases value by 1

let a4 = 9
console.log(--a4)
//output--> 8

let a5 = 12
console.log(--a5)
//output--> 11


//8) exponentiation operator ** : adds power to the value by given number

let a6 = 10
console.log(a6**2) // meaning: a6*a6 i.e. square of a6
//output--> 100

let a7 = 3
console.log(a7**3) // meaning: a7*a7*a7 i.e. cube of a6
//output--> 27

//----------------------------


// B) comparison operators:
// <, >, <=. >=, ==, !=, ===, !==


//1) value less than <

console.log(5 < 6)
console.log(7 < 8)


//2) value greater than >

console.log(10 > 2)
console.log(12 > 9)


//3) value less than or equal <=

console.log(5 <= 6)
console.log(4 <= 4)


//4) value grteater than or equal >=

console.log(11 >= 10)
console.log(15 >= 15)


//5) value equal ==

console.log(5 == 5)
console.log(6 == 6)
console.log(7 == 8)

console.log("--------------")


//6) value not equal !=

console.log(12 != 11)
console.log( 15 != 16)
console.log(20 != 20)


//7) value & data type both equal ===

console.log(4 === 4) // true // true // output: true
console.log(4 === '4') // true // false // output: false

console.log("------------------")


//8) value or data type not equal !== 

console.log(6 !== 6) // false // false // --> false  
console.log(6 !== '6') // false // true // --> true 
console.log('7' !== 6) // true // true // --> true
console.log('9' !== 9) // false // true // --> true 
//-----------------------

टिप्पण्या