Clear, practical technology insights About · Contact

Operator in JavaScript

Explore Operator in JavaScript with clear explanations, practical examples, and useful tips.

Published: 4 minutes read
Table of Contents

This guide covers operator in JavaScript with practical context and easy-to-follow details. Use it to understand the subject and apply the information confidently.

  1. Arithmetic operator
  2. Comparison operator
  3. Logical operators (or relations)
  4. Assignment operator
  5. Conditional operator

We now consider each operator one.

JavaScript supports the following arithmetic operators:

Assuming variable A holds value 10 and variable B holds value 20, then:

STATE DEBT AND DESCRIPTION1

+ (Addition)

Add two operands

Ex: A + B will result in 30

2

- (Subtraction)

Subtract the second operand from the first operand.

Ex: A - B will result in -10

3

* (Multiplication)

Multiply two operands

Ex: A * B will result in 200

4

/ (Division)

Divide the divisor by the divided number

Ex: B / A will result in 2

5

% (Split division)

The result is the remainder of the division.

Ex: B% A will result in 0

6

++ (Increase to 1)

Increase integer value to 1

Ex: A ++ will result in 11

7

- (Reduced 1)

Reduce an integer value to one

Ex: A-- will result in 9

Note - The plus (+) operand works with numbers as well as strings, for example: "a" + 10 will result in "a10".

For example

The following code shows how to use arithmetic operators in JavaScript:

 Set the variables to different values and then try.

Result:

 a + b = 43 
 a - b = 23 
 a / b = 3.3 
 a% b = 3 
 a + b + c = 43Test 
 a ++ = 33 
 b-- = 10 
 Đặt biến vào các giá trị khác nhau và thử thử . 

JavaScript supports the following comparison operators:

Suppose variable A holds value 10 and variable B holds a value of 20, then:

STATE DEBT AND DESCRIPTION1

= = (Equal)

Check if the value of the two operands is equal or not, if any, the condition becomes true.

Ex: (A == B) is not true.

2

! = (Unbalanced)

Check if the value of the two operands is balanced or not, otherwise the condition becomes true.

Ex: (A! = B) is true.

3

> (Larger)

Check if the value of the left operand is greater than the right operand, if any, the condition becomes true.

Ex: (A> B) is not true.

4

<(Smaller)

Check if the value of the left operand is less than the right operand, if any, the condition becomes true.

Frequently Asked Questions

What should I check before following these steps?

Confirm device and software compatibility, save important data, and make sure you have the required permissions, files, and account access.

Why might the process not work?

Common causes include outdated software, missing permissions, incompatible hardware, an unstable connection, or completing a step in the wrong order.

Can I undo the changes if necessary?

That depends on the tool or setting. Use built-in restore options when available, keep a backup, and record the original configuration first.

Was this article helpful?

Your feedback helps us improve.

Discussion

Reader Comments 0

Sign in with email or Google to join the discussion.