Math operation part 1

JavaScript Tutorial
Basic Concepts
Math Operators
34
1/5
               

Arithmetic Operators



Arithmetic operators perform arithmetic functions on numbers (literals or variables).
In the example below, the addition operator is used to determine the sum of two numbers.
var x = 10 + 5;
document.write(x);

// Outputs 15
Try It Yourself

You can add as many numbers or variables together as you want or need to.
var x = 10;
var y = x + 5 + 22 + 45 + 6548;
document.write(y);

//Outputs 6630
Try It Yourself

You can get the result of a stringexpression using the eval() function, which takes a string expression argument like eval("10 * 20 + 8") and returns the result. If the argument is empty, it returns undefined.
What will display in the result of the following statements?
var test=5+7;
document.write(test);
5+7
12
Test

Comments

Popular posts from this blog

Introducing object part 3

Comparison Operators part 2

Module 2