String (String), digital (Number), boolean (Boolean), array (Array), objects (Object), empty (Null), Undefined (Undefined).
var x = 5; // 现在 x 为数字
var x = "John"; // 现在 x 为字符串
The character string is stored (eg "Bill Gates") variables.
String can be quoted in any text. You can use single or double quotes:
var carname='Volvo XC60';
You can use quotation marks in the string, as long as the match is not surrounded by quotation marks to the string:
var answer="He is called 'Johnny'";
var answer='He is called "Johnny"';
You will learn more about the string of knowledge in the advanced section of the tutorial.
var x2=34; // //不使用小数点来写
Large or very small numbers through scientific (exponential) notation to write:
var z=123e-5; // 0.00123
You will learn more about digital knowledge in the advanced section of the tutorial.
Boolean (logic) can have only two values: true or false.
Boolean conditions commonly used in the test. You will be in a later section of this tutorial learn more about the conditions tested.
The following code creates the array named cars:
Or (condensed array):
Or (literal array):
Array index is zero-based, so the first item is , the second is , and so on.
You will be in a later section of this tutorial learn more about the array.
Objects are separated by braces. Within parentheses, property of the object name and value pairs (name: value) is defined. Property separated by commas:
In the example above the object (person) has three attributes: firstname, lastname and id.
Spaces and wrap irrelevant. Statement may span multiple lines:
firstname : "John",
lastname : "Doe",
id : 5566
Addressing object properties in two ways:
You will be in a later section of this tutorial learn more about the object of knowledge.
Undefined and Null
Undefined This value represents the variable does not contain a value.
You can set the value of the variable to null to clear the variables.
Declare variable types
When you declare a new variable, you can use the keyword "new" to declare its type:
var x= new Number;
var y= new Boolean;
var cars= new Array;
var person= new Object;