-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathOperators.js
102 lines (62 loc) · 2.37 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
93
94
95
96
97
98
99
100
101
102
//* Operators - JavaScript
/* Operators in JavaScript are symbols that perform operations on variables and values. Here there is one
description of some common operators in JavaScript: */
//? Arithmetic Operators:
//* 1. **Sum (+):**
let result = 5 + 3; // result is 8
//* 2. **Subtraction (-):**
let resut = 5 - 3; // result is 2
//* 3. **Multiplication (*):**
let rest = 5 * 3; // result is 15
//* 4. **Division (/):**
let res = 6 / 2; // result is 3
//* 5. **Module (%):**
let resultd = 7 % 3; // result is 1 (remainder of the division of 7 by 3)
//? Assignment Operators:
//* 6. **Assignment (=):**
let x = 10;
//* 7. **Assignment with Operation (+=, -=, *=, /=):**
let y = 5;
and += 3; // is the same as y = y + 3; // and now it is 8
//? Comparison Operators:
//* 8. **Equality (==):**
let a = 5;
let b = "5";
console.log(a == b); // true (value comparison)
//* 9. **Strict Equality (===):**
let aa = 5;
let bb = "5";
console.log(a === b); // false (value and type comparison)
//* 10. **Inequality (!=):**
let aaa = 5;
let bbb = 3;
console.log(a != b); // true (value comparison)
//? Logical operators:
//* 11. **And (&&):**
if (condition1 && condition2) {
// code if both conditions are true
}
//* 12. **Or (||):**
if (condition1 || condition2) {
// code if at least one of the conditions is true
}
//* 13. **Not (!):**
if (!condition) {
// code if condition is false
}
//? Increment and Decrement Operators:
//* 14. **Increment (++) and Decrement (--):**
let counter = 5;
counter++; // increment counter by 1 (counter is now 6)
counter--; // decrement the counter by 1 (counter is now 5 again)
//? Other Operators:
//* 15. **String Concatenation (+):**
let greeting = "Hello";
let name = "John";
let message = greeting + ", " + name + "!"; // "Hello John!"
//* 16. **Ternary Operator (? :):**
let age = 18;
let status = (age >= 18) ? "Adult": "Minor"; /* if age is greater than or equal to 18, status is
"Adult", otherwise it is "Minor" */
/* These are just some of the operators available in JavaScript. Combine and understand how they work
These operators are essential for writing effective and expressive code. */