Today Second day class in JavaScript. I shared the topics, What I learn Today.
Operators:
In programming and logic, an operator is a symbol or keyword that performs an action on one or more values (called operands).
Types of Operators
:
.Arithmetic Operators
.Assignment Operators
.Comparison Operators
.Logical Operators
.String Operators
.Type Operators
.Ternary Operator (Conditional)
.Nullish Coalescing
.Optional Chaining
ParseInt()
= method
String change into integer.
(NAN)
= not a number
Arithmetic Operators:
`+` Addition
`-` Subtraction
`*` Multiplication
`/` Division
`%` Modulus (remainder)
`**` Exponentiation
`++` Increment
`--` Decrement
Example:
10+5=15
"10"+5=105
"10"-string
10-5=5
10-15=-5
"10"-5=5
"7"*3=21
10/2=5
10%2=0
true-1
false-0
JavaScript
let i = 5;
let j = 7;
let result = ++i - --j + j-- + j++ - --i;
Initial values:
- `i = 5`
- `j = 7`
Now evaluate `result = ++i - --j + j-- + j++ - --i;`
Step-by-step evaluation:
1. *`++i`* → Pre-increment `i`:
- `i = 6`
- Expression becomes: `6 - ...`
2. *`--j`* → Pre-decrement `j`:
- `j = 6`
- Expression so far: `6 - 6 + ...`
3. *`j--`* → Post-decrement `j`:
- Value used = 6
- `j = 5` after this
- Expression so far: `6 - 6 + 6 + ...`
4. *`j++`* → Post-increment `j`:
- Value used = 5
- `j = 6` after this
- Expression so far: `6 - 6 + 6 + 5 + ...`
5. *`--i`* → Pre-decrement `i`:
- `i = 5`
- Final expression: `6 - 6 + 6 + 5 - 5`
Final Calculation:
`6 - 6 + 6 + 5 - 5 = 0 + 6 + 5 - 5 = 6 + 5 - 5 = 6`
Final Values:
- `i = 5`
- `j = 6`
- `result = 6`
Assignment Operators:
`=`
`+=`
`-=`
`*=`
`/=`
`%=`
`**=`
Comparison Operators:
`==` Equal to (loose equality)
`===` Equal value and type (strict equality)
`!=` Not equal to
`!==` Not equal value or type
`>` Greater than
`<` Less than
`>=` Greater than or equal
`<=` Less than or equal
Logical Operators:
&& Logical AND
! Logical NOT
String Operators:
+ Concatenation
+= Append and assign
Top comments (0)