xxxxxxxxxx
var additionOutput = 2 + 2; //addition
var subtractionOutput = 2 - 2; //subtraction
var multiplcationOutput = 2 * 2; //multiplcation
var divisionOutput = 2 / 2; //division
var exponentiation = 2**2; // Exponentiation
var modulus = 5 % 2; // Modulus (Remainder)
var unaryOperator = 1;
++unaryOperator; // Unary Operator Increment // ++ , --
xxxxxxxxxx
a = 90 + 13; //Addition
b = 72 - 23; //Subtraction
c = 23 * 7; //Multiplication
d = 12 ** 3; //Exponentation
e = 123 / 3; //Division
f = 139 % 2; //Modulus
g++; //Increment
h--; //Decrement
xxxxxxxxxx
/*
Arithmetic Operators
+ Addition
- Subtraction
* Multiplication
/ Division
** Exponentiation (ES7)
% Modulus (Division Remainder)
++ Increment [ Post / Pre ]
-- Decrement [ Post / Pre ]
*/
console.log(10 + 20);
console.log(10 + "Osama");
console.log(10 - 20);
console.log(10 - "Osama"); // NaN
console.log(typeof NaN);
console.log(10 * 20);
console.log(10 * -20);
console.log(20 / 5);
console.log(20 / 3);
console.log(2 ** 4);
console.log(2 * 2 * 2 * 2);
console.log(10 % 2);
console.log(11 % 2); // Remove 1
xxxxxxxxxx
Operator Name Example
+ Addition x + y
- Subtraction x - y
* Multiplication x * y
/ Division x / y
% Remainder x % y
++ Increment (increments by 1) ++x or x++
-- Decrement (decrements by 1) --x or x--
** Exponentiation (Power) x ** y
xxxxxxxxxx
let x = 5;
let y = 3;
// addition
console.log('x + y = ', x + y); // 8
// subtraction
console.log('x - y = ', x - y); // 2
// multiplication
console.log('x * y = ', x * y); // 15
// division
console.log('x / y = ', x / y); // 1.6666666666666667
// remainder
console.log('x % y = ', x % y); // 2
// increment
console.log('++x = ', ++x); // x is now 6
console.log('x++ = ', x++); // prints 6 and then increased to 7
console.log('x = ', x); // 7
// decrement
console.log('--x = ', --x); // x is now 6
console.log('x-- = ', x--); // prints 6 and then decreased to 5
console.log('x = ', x); // 5
//exponentiation
console.log('x ** y =', x ** y);