3. JavaScript Operators
3. JavaScript Operators
Operators
Contents
1. Overview
2. Assignment Operators
3. Arithmetic Operators
4. Comparison Operator
5. Logical Operators
6. String Operator
7. Ternary Operator
8. Nullish coalescing assignment (??=)
9. Nullish coalescing operator (??)
2
1. Overview
• Example:
· 2 + 3, here + is an operator that performs addition, and 2 and 3 are
operands.
• JavaScript Operator
1. Assignment Types:
Operator
5. Ternary
2. Arithmetic Operator
6. String Operators
3. Comparison Operator
7. Other Operators
4. Logical Operator
3
2. Assignment Operators
• Example:
let x = 5 (the = operator is used to assign value 5 to variable x)
• Example:
let number = 3 + 5
• Example:
const x = 5, y = 3
(x < 6) && (y < 5) // true
7
6. String Operators
• In JS, you can also use the + operator to concatenate (join) two or more
strings.
• Example:
console.log(‘hello’ + ‘world’)
Let a = ‘JavaScript’
a += ‘ tutorial’ // a = a + ‘ tutorial’
console.log(a)
• Output
helloworld
JavaScript tutorial 8
7. Ternary Operators
9
7. Ternary Operators (cont.)
• Note:
• You should try to avoid nested ternary operators whenever possible as
they make your code hard to read.
10
8. Nullish coalescing assignment (??=)
11
9. Nullish coalescing operator (??)
The nullish coalescing (??) operator is a logical operator that returns its right-
hand side operand when its left-hand side operand is null or undefined, and
otherwise returns its left-hand side operand.
12
Thank you
Perfect Practice, Does Perfect Thing
13