Sunday, 24 July 2016

JavaScript Arithmetic Operators

Operators
An operator is a symbol or a word that is reserved for some specific task or action.

Different JavaScript Operators

  • Arithmetic Operators
  • Assignment Operators
  • Comparison Operators
  • Logical Operators
  • Conditional Operator
Arithmetic Operators
This are used to perform some mathematical operations. Such as addition, subtraction, multiplication etc.
Different Arithmetic Operators 
  • + : adds two numbers or joins two strings. this operator also represents a positive number when it is prefixed to a number.
  • - : subtracts two numbers or represents a negative number.
  • * : multiplies two numbers.
  • / : divides two numbers and returns the quotient,
  • % : divides two numbers and returns the remainder.
  • ++ : increment the value of the number by 1. it can be prefixed or suffixed to a number. when prefixed, the value is incremented in the current statement, and when suffixed, the value is incremented after the current statement.
  • -- : decrements the value of the number by 1. it can be prefixed or suffixed to a number. when prefixed, the value is decremented in the current statement, and when suffixed, the value is decremented after the current statement.
Example

<!DOCTYPE html>
<html>
<head>
    <title>javaScript Arithmetic Operators</title>
</head>
<body>
    <h1>JavaScript Arithmetic Operators</h1>
    <script>
        var number1 = 2567;
        var number2 = 50;

        document.write(number1 + number2 + "<br />");
        document.write("Indian" + " Ocean" + "<br />");
        document.write(number1 - number2 + "<br />");
        document.write(number1 / number2 + "<br />");
        document.write(number1 % number2 + "<br />");
        document.write(number1++  + "<br />");
        document.write(++number1  + "<br />");
        document.write(number2-- + "<br />");
        document.write(--number2 + "<br />");
    </script>
</body>
</html>


0 comments:

Post a Comment