JAVASCRIPT

 Home  Computers & Internet  Web Programming JAVASCRIPT
What is Javascript?
Javascript Placement
Syntax
Reserved Words
Variables
Data Types
Escaping Characters
Concatenation
Arithmetic Operators
Assignment Operators
Comparison Operators
Boolean Operators
Conditional Operator
If Statements
Else If Statements
If Else Statements
Switch Statements
While Loops
For Loops
Do While Loops
Break Statement
Continue Statement
prompt()
alert()
Date()
Event Handlers
String Object Methods
Math Object Methods
Window Object Methods

JAVASCRIPT ARITHMETIC OPERATORS

As in other programming languages, javascript also allows you to perform arithmetic calculations with +, -, *, /, %, ++ and --.

The following are examples of arithmetic calculations using these operators:

Addition ( + )

var num1=20 + 20;

alert(num1);// outputs 40

var num1=1.14;
var num2=3.16;
var num_total= num1 + num2;

alert(num_total);// outputs 4.3

Subtraction ( - )

var num1=20 - 20;

alert(num1);// outputs 0

var num1=5;
var num2=3.2;
var num_total= num1 - num2;

alert(num_total);// outputs 1.8

Multiplication ( * )

var num1=10 * 30;

alert(num1);// outputs 300

var num1=34;
var num2=2;
var num_total= num1 * num2;

alert(num_total);// outputs 68

Division ( / )

var num1=4000 / 40;

alert(num1);// outputs 100

var num1=60;
var num2=2;
var num_total= num1 / num2;

alert(num_total);// outputs 30

Modulus - remainder after a division ( % )

var num1=45 % 40;

alert(num1);// outputs 5

var num1=60;
var num2=2;
var num_total= num1 % num2;

alert(num_total);// outputs 0 (no remainder)

Increment Variable By 1( ++ )

var num1=200;
num1++

alert(num1);// outputs 201

Decrement Variable By 1( -- )

var num1=200;
num1--

alert(num1);// outputs 199

Home | Privacy Policy | Terms Of Use | Contact Us