Subtraction Operator in JavaScript



Subtraction Operator

In JavaScript, arithmetic Subtraction Operator is used to find the difference of a number from another number.

Syntax

- symbol is used for arithmetic Subtraction operator.

Arithmetic subtraction operator takes two values/variables as operands and returns the difference of right side operand from the first operand.

a - b  //variables
6 - 4  //values

More than one value/variable can be subtracted from a value in a single expression by chaining subtraction operator.

a - b - c - d        //variables
6 - 4 - 5 - 10 - 85  //values

Examples

1. Find the subtraction of b from a.

var a = 10;
var b = 25;

var diff = a - b;

console.log(diff);

2. Subtraction of more than one value/variable from a value.

var a = 10;
var b = 25;
var c = 14;

var diff = a - b - c;

console.log(diff);