DEV Community

Bhuvana Sri R
Bhuvana Sri R

Posted on

Day 2 of JavaScript

Types of Operators:

  • Arithmetic Operator
  • Boolean Operator
  • Increment & Decrement Operator
  • Comparsion Operator
  • Conditional Operator
  • Logical Operator

Arithmetic Operator

It has two Operands and one operator.The operator are +,-,,/,%,*.
Example:

  • 10+5=15,
  • "10"+5=105(It concatenate the string and int).
  • "10"-5=5(Because Javascript dynamical programming language .So the value automatical convert a string as int using parseInt method but it's only convert the num string).
  • 10*2=20,10/2=5,10%2=0,2**3-2*2*2=8.

(Convert String into Int using parseInt)

Boolean Operator

  • In boolean value True is 1.
  • In boolean value False is 0.

Example:true+1=2,false-2=-2

Increment & Decrement Operator

  • PostIncrement:(i++)

It first assign the value and then increment.
Example:
i=5;
log(i++);//5

  • Postdecrement:(i--)

It first assign the value and then Decrement.
Example:
i=5;
log(i--);//5

  • Preincrement:(i--)

It first increment the value and then assign.
Example:
i=5;
++i;
log(i);//6

  • Predecrement:(i--) It first decrement the value and then assign. Example: i=5; --i; log(i);//4

Comparsion Operator

It compare both the value and return the boolean value .

  • == Method:
    Example:
    == Method
    5==5 //true
    "5"==5(In this case it return the true value because it check only the values not the datatypes)
    === Method
    "5"===5(In this case it return the flase value because it check both the values and the datatypes)

  • Greaterthan Operator & lessthan Operator(>,<)
    Example:7>5//True
    5<7//true

  • Greaterthan or equal to Operator & lessthan or equal to Operator(>=,<=)
    Example:5<=5//true

Logical Operator

  • OR ->||
  • AND ->&&
  • NOT ->!

OR(||) :
If any one condition is true it return true.

AND(&&):
It return true only when Both the condition are true.otherwise it return flase.

Top comments (0)