Javascript Operator ٠٦٣١٥٠
Javascript Operator ٠٦٣١٥٠
Example
Assign values to variables and add them together:
Example
Assignment
var x = 10;
Adding
var x = 5;
var y = 2;
var z = x + y;
Multiplying
var x = 5;
var y = 2;
var z = x * y;
Assignment
var x = 10;
x += 5;
Example
var txt1 = "John";
var txt2 = "Doe";
var txt3 = txt1 + " " + txt2;
John Doe
The += assignment operator can also be used to add (concatenate) strings:
Example
var txt1 = "What a very ";
txt1 += "nice day";
Adding two numbers, will return the sum, but adding a number and a string will return a
string:
Example
var x = 5 + 5;
var y = "5" + 5;
var z = "Hello" + 5;
10
55
Hello5
If you add a number and a string, the result will be a string!
Any numeric operand in the operation is converted into a 32 bit number. The result is
converted back to a JavaScript number.