"I am Saqib Jahangir. A passionate vlogger, software engineer, trainer and avid traveler with a deep love for exploring the hidden gems of our beautiful planet. With a strong foundation in Application Development, Application Architecture & Database Design and Product Management, I bring over a decade of hands-on experience building secure, scalable, and resilient web applications for a diverse range of industries."

Operators and Expressions

 

Operators in JavaScript allow you to perform operations on variables and values, creating expressions that produce new values.

Arithmetic Operators

Used to perform basic math operations:

Operator

Description

Example

Result

+

Addition

5 + 3

8

-

Subtraction

5 - 3

2

*

Multiplication

5 * 3

15

/

Division

10 / 2

5

%

Modulus (remainder)

7 % 3

1

++

Increment

let a = 1; a++;

2

--

Decrement

let b = 2; b--;

1


Assignment Operators

Used to assign values to variables, often combined with arithmetic:

Operator

Description

Example

Result

=

Assign

x = 10

x becomes 10

+=

Add and assign

x += 5

x = x + 5

-=

Subtract and assign

x -= 3

x = x - 3

*=

Multiply and assign

x *= 2

x = x * 2

/=

Divide and assign

x /= 4

x = x / 4

%=

Modulus and assign

x %= 3

x = x % 3


Comparison Operators

Compare values and return a Boolean (true or false):

Operator

Description

Example

Result

==

Equal (value only)

5 == '5'

true

===

Equal (value and type)

5 === '5'

false

!=

Not equal (value only)

5 != 10

true

!==

Not equal (value/type)

5 !== '5'

true

< 

Less than

3 < 5

true

> 

Greater than

10 > 7

true

<=

Less than or equal

5 <= 5

true

>=

Greater than or equal

7 >= 10

false


Logical Operators

Used to combine or invert Boolean values:

Operator

Description

Example

Result

&&

Logical AND

true && false

false

`

`

Logical OR

!

Logical NOT

!true

false

String Concatenation

The + operator can also join (concatenate) strings:

let greeting = "Hello, " + "world!";
console.log(greeting);  // Output: Hello, world!

You can also combine variables and strings:

let name = "Alice";
console.log("Hi, " + name + "!");  // Output: Hi, Alice!

 

Popular Posts

Operators (Arithmetic, Comparison, Logical)

Functions (Built-in & User-defined)