-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathOperators.js
98 lines (67 loc) · 2.35 KB
/
Operators.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
/*---------------------------------------------------------
author: kallol chakraborty
program no: 003
program description: Operators
time complexity: O(1)
space complexity: O(1)
date: 11/11/2021
----------------------------------------------------------*/
var number1 = 6;
var number2 = 7;
console.log("Sum:", number1 + number2);
console.log("Product:", number1 * number2);
// boolean output
console.log(number1 > number2);
console.log("Data Type:", typeof (number1 > number2))
// discount: ((listingPrice - Selling)/listingPrice) * 100
console.log("Discount Pecentage:", ((number2 - number1) / number2) * 100);
// rounding up
console.log("Rounded Discount Pecentage:", Math.round(((number2 - number1) / number2) * 100));
// ternery operator
var authenticated = false;
authenticated ? console.log("LogOut") : console.log("LogIn");
//exponential
let x = 3;
let y = 3;
console.log(x ** y);
//post-increment : first assignement then increment, displays 3 but value will be 4
console.log(x++);
console.log(x);
//pre-increment : first increment then assignment, displays 5 as the 1 is added to x(4)
console.log(++x);
//same in case of decrement
//strict equality: (type + value) check
console.log(1 === 1);
//lose equality: No type check
console.log('1' == 1);
//ternery operator -> condition ? True : False;
// if the customer has more than 100 points then the customer is a Gold customer else Silver
let points = 110;
let type = points > 100 ? 'Gold' : 'Silver';
console.log(`The customer type is : ${type}`);
//Logical operators
//Logical AND(&&): true if all the operands are true
console.log('Logical And output :', false && true)
//Logical OR(||) : true is one of the operands is true
console.log('Logical OR output :', true || false);
//Logical Not(!)
points = 90;
type = points > !100 ? 'Silver' : 'Gold';
console.log(`The customer type is : ${type}`);
//Anything that is not Falsy -> Truthy
console.log(false || 1);
console.log(false || 'Kallol');
//Short-Circuiting : after the 2nd Operand, all the other operands are omitted
console.log(false || 1 || 2);
let userColor = undefined;
let defaultColor = 'Red';
let currentColor = userColor || defaultColor;
console.log(currentColor);
//Bitwise Operators
// 1 = 00000001 (8 bit)
// 2 = 00000010
//Bitwise OR
console.log(1 | 44);
//Bitwise AND
console.log(1 & 44);
//Application: Permission Systems