Friday 9 January 2015

What is an operator?

Simple answer can be given using expression 4 + 5 is equal to 9. Here 4 and 5 are called operands and + is called operator. JavaScript language supports following type of operators.
  • Arithmetic Operators
  • Comparision Operators
  • Logical (or Relational) Operators
  • Assignment Operators
  • Conditional (or ternary) Operators
Lets have a look on all operators one by one.

The Arithmatic Operators:

There are following arithmatic operators supported by JavaScript language:
Assume variable A holds 10 and variable B holds 20 then:
OperatorDescriptionExample
+Adds two operands A + B will give 30
-Subtracts second operand from the first A - B will give -10
*Multiply both operands A * B will give 200
/Divide numerator by denumerator B / A will give 2
%Modulus Operator and remainder of after an integer division B % A will give 0
++Increment operator, increases integer value by one A++ will give 11
--Decrement operator, decreases integer value by one A-- will give 9

Note: Addition operator (+) works for Numeric as well as Strings. e.g. "a" + 10 will give "a10".

No comments:

Post a Comment