Latest web development tutorials
×

JavaScript Tutorial

JavaScript Tutorial JavaScript Introduction JavaScript usage JavaScript Output JavaScript grammar JavaScript Statement JavaScript Notes JavaScript variable JavaScript type of data JavaScript Object JavaScript function JavaScript Scope JavaScript event JavaScript The string JavaScript Operator JavaScript Comparison JavaScript If...Else JavaScript switch JavaScript for JavaScript while JavaScript Break & Continue JavaScript typeof JavaScript Type conversion JavaScript Regular Expressions JavaScript error JavaScript debugging JavaScript Variable promotion JavaScript Strict mode JavaScript Use errors JavaScript Form validation JavaScript Keep the keyword JavaScript JSON JavaScript void JavaScript Code specification

JS function

JavaScript Function definition JavaScript Function parameter JavaScript Function call JavaScript Closure

JS HTML DOM

DOM Introduction DOM HTML DOM CSS DOM event DOM EventListener DOM element

JS Advanced Tutorial

JavaScript Object JavaScript Number JavaScript String JavaScript Date JavaScript Array JavaScript Boolean JavaScript Math JavaScript RegExp Object

JS Browser BOM

JavaScript Window JavaScript Window Screen JavaScript Window Location JavaScript Window History JavaScript Navigator JavaScript Pop-ups JavaScript Timing events JavaScript Cookies

JS Library

JavaScript Library JavaScript test jQuery JavaScript test Prototype

JS Examples

JavaScript Examples JavaScript Object instance JavaScript Browser object instance JavaScript HTML DOM Examples JavaScript to sum up

JS Reference Manual

JavaScript Object HTML DOM Object

JavaScript Operators

= Operator for assignment.

+ Operator for VAT.


= Operator is used to JavaScript variable.

Arithmetic operator + is used to add value.

Examples

Specify the value of the variable, and the values ​​are added:

y=5;
z=2;
x=y+z;

After the above statement is executed, the value of x is:

7

try it"


JavaScript Arithmetic Operators

y = 5, the following table explains these arithmetic operators:

运算符 描述 例子 x 运算结果 y 运算结果 在线实例
+ 加法 x=y+2 7 5 实例 »
- 减法 x=y-2 3 5 实例 »
* 乘法 x=y*2 10 5 实例 »
/ 除法 x=y/2 2.5 5 实例 »
% 取模(余数) x=y%2 1 5 实例 »
++ 自增 x=++y 6 6 实例 »
x=y++ 5 6 实例 »
-- 自减 x=--y 4 4 实例 »
x=y-- 5 4 实例 »


JavaScript Assignment Operators

JavaScript assignment operator is used to assign values ​​to variables.

Given x = 10 and y = 5, the table below explains the assignment operator:

运算符 例子 等同于 运算结果 在线实例
= x=y x=5 实例 »
+= x+=y x=x+y x=15 实例 »
-= x-=y x=x-y x=5 实例 »
*= x*=y x=x*y x=50 实例 »
/= x/=y x=x/y x=2 实例 »
%= x%=y x=x%y x=0 实例 »


+ Operator for string

+ Operator is used to add text or string variable (linked).

For the connection of two or more string variables together, use the + operator.

Examples

For the connection of two or more string variables together, use the + operator:

txt1="What a very";
txt2="nice day";
txt3=txt1+txt2;

txt3 operation results are as follows:

What a verynice day

try it"

To increase the space between two strings, we need to insert spaces into a string:

Examples

txt1="What a very ";
txt2="nice day";
txt3=txt1+txt2;

After the above statement is executed, the value of the variable txt3 included are:

What a very nice day

try it"

Or the space into the expression ::

Examples

txt1="What a very";
txt2="nice day";
txt3=txt1+" "+txt2;

After the above statement is executed, the value of the variable txt3 included are:

What a very nice day

try it"


Strings and numbers adder

Two numbers together and returns the sum of the numbers and, if the numbers are added and the string and returns a string following examples:

Examples

x=5+5;
y="5"+5;
z="Hello"+5;

x, y, and z output is:

10
55
Hello5

try it"

Rule: If the sum of the numeric string, the result will be a string!