Arithmetic Vs Comparison Operator – JavaScript Tutorial


Arithmetic and Comparison Operator. In this article, we will take a brief look at Operators in JavaScript. But first, before we move on we need understand what is an operator. So let us first start this article from the operator and end up with the comparison operator. We mostly use the operator to specify our expressions because using operators you can compare two values you can add multiply divide and do so many things.

now the question is what is the operator? In simple words operator is just an expression result in a value. Operators take one or more operands to produce a result. For example, In this example, i will say 1 + 2. Nowhere 1 and 2 is operands and Plus sign is an operator. in the programming language, you often see operand called argument.

So we will start our operators from basic mathematics. Now let me move on to the arithmetic and comparison operator. So we’ll discuss arithmetic operator first. As long as I know you feel comfortable with arithmetic operator because you learned most of them in the school.

Arithmetic Operator

arithmetic and comparison

  1. ( + ) Addition
    • Addition is use for addition and also for concatenation.
      • For Example,
      • this operator evaluates value right to left.

 

  1. ( – ) Subtraction
    • Subtraction used to subtract two values.
      • For Example,

        this operator evaluates value right to left.

 

  1. ( / ) Division
    • The division Operator used to divide two values.
      • For Example,

        • this operator evaluate value left to right

 

  1. ( * ) Multiplication
    • The multiplication use to multiply two values.
    • For Example,

      • this operator evaluates value left to right

 

  1. ( % ) Reminder
    • Reminder return reminder after division.
    • For Example,

      • this operator evaluates value left to right.

 

  1. ( – ) Unary Negation
    • Unary negation use to specify the negative value.
    • For example, It means if y is equal to 10 then -y will be -10
    • This operator evaluates the value right to left.

 

  1. ( + ) Unary Plus
    • Unary negation use to specify the Positive value.
    • For example, It means if y is equal to -10 then +y will be 10
    • This operator evaluates the value right to left

 

  1.  ( ++ ) Pre-increment
    • ++y Used to increment the value by one add evaluate to a new value.
    • This operator evaluates the value right to left
    • For example,
  2. ( ++ ) Post-increment
    • y++ Used to increment the value by one.
    • This operator evaluates the value right to left
    • For example,
  3. ( — ) Pre-decrement
    • –y use to decrease the value by one. And evaluate to a new value.
    • This operator evaluates the value right to left.

 

  1. ( — ) Post-decrement
    • y– used to decrease the value by one. Evaluate to the value of y before the increment.
    • This operator evaluates the value right to left.

 

Comparison Operator

As the name implies, Comparison operator compares two different values. Broadly speaking there are three types of the comparison operator. Strict equality abstract equality and relational equality. We will take a look at all these three types in the next tutorial but now just take a look how comparison operator looks like.

arithmetic and comparison

So the following is the comparison operator to compare two different values.

  1. ( < ) Less Then
    • less than operator evaluates to true if its first operand is less than its second operand. Otherwise, it evaluates to false. Less than operator evaluate to value left to right.
    • For example, 
  2.  ( > ) Greater Than
    • Greater than operator evaluates to true if its first operand is greater than its second operand. Otherwise, it evaluates true false.  Greater than operator evaluates to value left to right.
    • For example,
  3. ( <= ) Less Than or Equal
    • So less than or equal to operator evaluates to true if  Its first or brand is less than or equal to its a second or operand. Otherwise, it evaluates to false. Less than or equal to evaluate to value left to right.
    • For example,

       
  4. ( <= ) Greater Than or Equal 
    • Greater than or equal to operator evaluate to true if its first operand is greater than or equal to its second operand. Otherwise, it evaluates to false. Greater than or equal to evaluate to value left to right.
    • For example,

       

That’s it. Now our Arithmetic and comparison operator is completed. In the next article, we will explore more operators and learn the complete set of javascript operators. So that is all for this article, We will see you in the next article.