JavaScript contains 7 data types: 字符串(String)、数字(Number)、布尔(Boolean)、数组(Array)、对象(Object)、空(Null)、未定义(Underfined)。
You can learn String in a example:
var myname = "JavaScript"
var language = myname + " is a scripting language."
document.write(language)
And link it in html, output is :
JavaScript is a scripting language.
Other data type’s declaration is similar.
JS do not like other language, it’s Number type only one type, which can be a Int(integer) or Float(decimal ).
var age = 20
var length = 1.5
var z = 123e-5
In code above, you notic “123e-5”,“e” or “E” stands for ten to the e (It would be easy to understand it if you have learn C or other High-level programming languages. ). Here, “123e-5” mean “0.00123”.
Boolean only two value: ture and false.
var x = ture
var y = false
You can use Array() object to creat array.
It may be difficult to understand what is “object”, but it doesn’t matter, after learning the JAVA or other Object-oriented programming languages, you will get it. But you have not learn it , so just Remember it.
var language = new Array() /*remmember this format */
language[0] = "python"
language[1] = "JavaScript"
language[2] = "Html"
/*maybe you want a easy way*/
var language = new Array("python", "JavaScript", "Html")
/*or use list to creat array*/
var language = ["python", "JavaScript", "Html"]
/*and then uses a for loop to iterate over the array to output, like in C */
for (i = 0; i < 3; i++) {
document.write(language[i] + "")
}
output :
python
JavaScript
Html
In JavaScript, almost everything is an object.
An object is also a variable, but an object can contain multiple values (multiple variables).
In JavaScript, objects are like “containers” for variables.
Typically, JavaScript objects hold key-value pairs.
Key-value pairs are usually written as name: value (the key and value are separated by a colon).
Key-value pairs in JavaScript objects are called object properties.
在 JavaScript中,几乎所有的事物都是对象。对象也是一个变量,但对象可以包含多个值(多个变量)。
在JavaScript中,对象像是变量的“容器”。
通常,JavaScript 对象中放着键值对(键:值)。
键值对通常写法为 name : value (键与值以冒号分割)。
键值对在 JavaScript 对象通常称为对象属性。
You can declare a object like this:
var student = {
name: "zhzhang",
ID: "2019611000",
age: 20,
dorm: "JingYi"
};
Object’name is student, in this object,have name, ID, age, dorm.
You can change the value of an object’s properties by using “.” , you can get the value of an object in the same way :
var student = {
Name: "zhzhang",
ID: "2019611000",
age: 20,
dorm: "JingYi"
};
student.dorm = "ZhiXing"
document.write(student.dorm)
Here is output:
ZhiXing
NULL mean no value, value is empty.
Undefined means the variable is declared but no value is assigned.
2021.1.14.by zhang