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 :: what is a for loop in javascript 
Javascript :: how to clear a function in javascript 
Javascript :: current date jquery and current day 
Javascript :: jquery effect methods 
Javascript :: Create Your Own Node Module 
Javascript :: javascript create object empty 
Javascript :: jquery label with text 
Javascript :: footer bottom 
Javascript :: angular object sort by key 
Javascript :: javascript array iteration methods 
Javascript :: js access array in array 
Javascript :: convert integer month to string month react native 
Javascript :: use jquery in project using NPM 
Javascript :: radio button not checked 
Javascript :: convert UTC date to Indonesian local date format 
Javascript :: setTimeout(() = { console.log(i);}, 100); 
Javascript :: js number round to each 15 
Javascript :: filter js object array based on multiple parameters 
Javascript :: min max value javascript 
Javascript :: Iterate Through the Keys of an Object 
Javascript :: d3.js 
Javascript :: moment iso string 
Javascript :: networkx get nodes 
Javascript :: array==null array.length java script 
Javascript :: how to use msg.send instead of msg.reply discord.js javascript 
Javascript :: csurf in express 
Javascript :: js how to have an onclick inside of another onClick 
Javascript :: usestate hook callback 
Javascript :: find element causing vertical overflow 
Javascript :: round down js 
ADD CONTENT
Topic
Content
Source link
Name
1+3 =