Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

javascript Arithmetic operators

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 // ++ , --
Comment

js arithmetic operators

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
Comment

Arithmetic operators in JavaScript

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);
Comment

JavaScript Arithmetic Operators

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
Comment

javascript Arithmetic Operators

/*
  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
Comment

PREVIOUS NEXT
Code Example
Javascript :: add tab to textarea javascript 
Javascript :: Page Height Bottom 
Javascript :: ifsc code yup validation 
Javascript :: difference between var and let 
Javascript :: display amount with currency for jquery 
Javascript :: export all functions 
Javascript :: vuex state from another module 
Javascript :: npm react copy to clipboard 
Javascript :: time js code 
Javascript :: set in javascript 
Javascript :: square node js 
Javascript :: remove classname to node 
Javascript :: reactjs radio button onchange 
Javascript :: list javascript 
Javascript :: Random Integer 1-10 
Javascript :: find input by value attribute javascript 
Javascript :: uselocation react 
Javascript :: how to move div using jquery 
Javascript :: how to copy value instead of reference js 
Javascript :: js substring first 4 numbwe 
Javascript :: formik and yup reactjs 
Javascript :: javascript set time to start of day 12 am 
Javascript :: create app with a specific react version 
Javascript :: remove duplicates from array of objects 
Javascript :: react download file from express res.download 
Javascript :: adjacent elements product javascript 
Javascript :: __v mongodb 
Javascript :: codeigniter 3 if ajax request 
Javascript :: how to get the computer date and time jquery 
Javascript :: react native counter 
ADD CONTENT
Topic
Content
Source link
Name
1+5 =