The arthemetic operators are those that use two or more operands in the form of constants or variables and return single value as results. The value of arithmetic expressions are stored in a variable or used in other expressions.
We shall discuss each one of them with examples.
The addition operator also known as plus(+), adds two numbers and output the result. The syntax for addition operator is given below.
//Syntax <variable> = <variable1> + <variable2> + ... + <variableN>;
//variable declarations var A = 10; var B = 23; var C = A + B; //addition console.log(c);
Subtraction operator takes two operand and subtract the value of second operand from the first. The result is single value stored in a variable to display or used in a new expression. The subtraction is a left-to-right operation.
//Syntax <variable> = <variable1> - <variable2> - ... - <variableN>;
//variable declaration var A = 20; var B = 12; var C = A - B; //subtraction console.log(C); //output
The multiplication operator takes two or more operands and multiply (*) them to get a single number result. The operands are constants or variables . Here is the syntax for multiplication.
//Syntax <variable> = <variable1> * <variable2> * ... * <variableN>;
//variable declaration var A = 5; var B = 25; var C = A * B; //multiply console.log(C); //output
Division operator or divide operation takes two operands and divide the first number with the second number. You get a result called the quotient of the division. The first number is called dividend and the second called divisor.
//Syntax <variable> = <variable1>/<variable2>;
//variable declaration var A = 440; var B = 4; var C = A/B; //division console.log(C); //output
Unlike division, the remainder operator will give remainder of a division , not quotient even if it is a zero. The is a special symbol to indicate remainder division (%).
//Syntax <variable> = <variable1> % <variable2>;
The second number divides the first number and give the remainder that gets stored in the variable to the left.
//variable declaration var A = 18; var B = 4; var C = A % B; //remainder division console.log(C); //output
//variable declaration var A = 6; var B = 2; var C = A ** B; // exponential operation console.log(C);//output
In future post, we will discuss about more such operators.