Operators are the symbols between the value that are support following types of the operator:
Arithmetic Operators
Comparison Operators
Assignment Operators
Conditional or ternary Operators
Logical or Relational Operators
JavaScript Type Operators
1 Arithmetic Operators
Following are the Arithmetic Operator of JavaScript:
Assume C = 30 and D = 10 then output of example.
Operator

Description

Example

+

Addition

C + D then 40



Subtraction

C – D then 20

*

Multiplication

C * D then 300

/

Division

C / D then 3

%

Modulus

C % D then 0

++

Increment

C++ then 31



Decrement

Cthen 29

Note: Addition Operator is work for both numeric and string. For Example: “A” + 10 = “A10”
2 Comparison Operators
Following are the Comparison Operators:
Assume A = 30 and B = 10 then output of example:
Operator

Description

Example

==

equal to

A == B is false

===

equal value and equal type

A === B is false

!=

not equal

A != B is true

!==

not equal value or not equal type

A !== B is true

>

greater than

A > B is true

<

less than

A < B is false

>=

greater than or equal to

A >= B is true

<=

less than or equal to

A <= B is false

3 Assignment Operators
Following are the Assignment Operators:
Assume variable A = 30 and variable B = 10 then output of example:
Operator

Description

Example

Same As

=

Simple Assignment

Result = A + B then 40 will be for Result

A = B

+=

Add and Assignment

A += B

A = A + B

=

Subtract and Assignment

A = B

A = A  B

*=

Multiply and Assignment

A *= B

A = A * B

/=

Divide and Assignment

A /= B

A = A / B

%=

Modules and Assignment

A %= B

A = A % B

4 Conditional or ternary Operators
The conditional operator is a ternary operator. It takes three operands. It will return first value if the condition is true and returns second value when the condition is false.
Syntax: condition? truevalue: falsevalue;
Example: Assume A = 20 and B = 10
(A > B)? "A is Bigger than B”: "B is Smaller than A"
Output: A is Bigger than B
5 Logical or Relational Operators
Following are the logical operator:
Assume variable A = 20 and variable B = 40, then output of example:
Operator

Description

Example

&&

logical and

(C && D) is true



logical or

(C  D) is true

!

logical not

(C && D) is false

6 JavaScript Type Operators
Following are the JavaScript Type of Operators
Operator

Description

typeof

It will return the type of a variable.

instanceof

It will return true if an object is an instance of an object type.

No comments:
Post a Comment