Wednesday, 29 May 2024

Java Script: Operators

 Operators are a type of command. They perform operations on variables and/or literals and produce a result. they are the symbols between values that allow different operations like addition, subtraction, multiplication, and more.

JavaScript has dozens of operators, so let’s focus on the ones you’re likely to see most often.


Arithmetic


+

Addition

-

Subtraction

*

Multiplication

/

Division

%

Modulus


The + operator adds two numbers.

EXAMPLE:

1 + 5;

OutPut

6


The - operator subtracts one number from another.

EXAMPLE:

12 - 5;

OutPut

7


The * operator multiplies two numbers. Notice it’s an asterisk and not the × symbol commonly used in math.

EXAMPLE:

12 * 5;

OutPut

60


The / operator divides one number by another. Notice it’s a forward slash and not the ÷ symbol commonly used in math.

EXAMPLE:

12 / 4;

OutPut

3

JavaScript expressions follow an order of operations, so even though + is written first in the following example, the multiplication happens first between the last two numbers and *.

EXAMPLE:

1 + 100 * 5;

OutPut

501


Grouping

() operator groups other values and operations. Code located between parentheses evaluates first as JavaScript solves each operation moving from left to right.

Adding the grouping operator to the previous example causes 1 + 100 to evaluate first.

EXAMPLE:

(1 + 100) * 5;

OutPut

505


Concatenation

The + operator can also concatenate strings, which is another way of saying it can add them together.

EXAMPLE:

"Balaji" + "Tech";

OutPut

BalajiTech


Assignment

The = operator assigns values. It’s used for setting the value of variables.

EXAMPLE:

var dinner = "sushi";


No comments:

Post a Comment

Interactive Report: Introduction to the Internet of Things (IoT) ...

Popular Posts