JavaScript Operators- Tutorialpath

Welcome to all our readers on our website at www.tutorialpath.com. As you all know that here on our website we will provide you lots of information related to the latest and newly introduced technology which help you to get updated with the latest tech. Here you will get all the useful information which is required in this tech world. As you know technology is one of the trending part in this world. So, here again we came up with a latest and new tech information which is related to the process of creating JavaScript Operators. With the help of this article you will get to know the complete process of how to create JavaScript Operators in a step by step manner. So, simply have a look to this article and grab all the useful information which is going to be very helpful for you.

JavaScript also includes operators like other languages. An operator performs some operation on a single or multiple operand (data value) and produces a result.

Basic Example:

7 + 4 is equal to 11. Here 7 and 4 are called operands and ‘+’ is called the operator. JavaScript supports the following types of operators.

  • Arithmetic Operators
  • Comparison Operators
  • Logical (or Relational) Operators
  • Assignment Operators
  • Conditional (or ternary) Operators

Arithmetic Operator:

Arithmetic operators are used to perform mathematical work between numerical operations.

Assume variable A holds 10 and variable B holds 20, then −

Sl. No Operator & Description
1 + (Addition)

Adds two operands

Ex: A + B will give 30

2 – (Subtraction)

Subtracts the second operand from the first

Ex: A – B will give -10

3 * (Multiplication)

Multiply both operands

Ex: A * B will give 200

4 / (Division)

Divide the numerator by the denominator

Ex: B / A will give 2

5 % (Modulus)

Outputs the remainder of an integer division

Ex: B % A will give 0

6 ++ (Increment)

Increases an integer value by one

Ex: A++ will give 11

7 — (Decrement)

Decreases an integer value by one

Ex: A– will give 9

Assignment Operators

Assignment operators are used to assign values to JavaScript variables.

Given that x = 10 and y = 5, the table below explains the assignment operators:

Operator Example Same As Result in X
= x = y x = y x = 5
+= x + = y x = x + y x = 15
-= x  – = y x = x – y x = 5
*= x  * = y x = x * y x = 20
/= x  / = y x = x / y x = 2
%= x  % = y x = x % y x = 0

Comparison Operators

The JavaScript comparison operator compares the two operands. The comparison operators are as follows:

Operator Description Example
== Is equal to 10==20 = false
=== Identical (equal and of same type) 10==20 = false
!= Not equal to 10!=20 = true
!== Not Identical 20!==20 = false
> Greater than 20>10 = true
>= Greater than or equal to 20>=10 = true
< Less than 20<10 = false
<= Less than or equal to 20<=10 = false

Logical (or Relational) Operators

There are many types of Logical Operators in JavaScript –

Operator Description Example
&& (Logical AND) It checks if the two operations are non-zero (0, false, undefined, null or “” treated as zero), if yes, 1 otherwise return to 0. (10==20 && 20==33) = false
|| (Logical OR) It checks if either one is non-zero (0, false, undefined, null or “” is considered null). Thus || Returns true if either operand is true and if both are false it is false. (10==20 || 20==33) = false
! (Logical Not)

This reverses the Boolean result of the operand (or position).

!(10==20) = true

Conditional (or ternary) Operators

The conditional operator first evaluates an expression to a true or false value and then executes one of the two statements based on the result of the evaluation.

Sr.No. Operator and Description
1 ? : (Conditional )

If Condition is true? Then value X : Otherwise value Y

 

Conclusion

So, hopefully we have shared all the basic steps that help you JavaScript Operators.  In this tutorial, you have to learn basic several ways for JavaScript .

Leave a Reply

Your email address will not be published. Required fields are marked *