One, simple data type
undefined: This value indicates that the variable does not contain a value.
If the return value of typeof(data) is the string 'undefined', that is, the data type of the variable data is undefined. That is, data does not contain a value.
var x // x is undefined
null : This value indicates that the variable is empty.
boolean : true or false for a boolean value.
number : JavaScript has only one number type. Numbers may or may not have a decimal point. Such as: 123 and 12.3.
srting : As we mentioned earlier, strings are carriers of characters and must be surrounded by pairs of quotes. For example: 'hello world!'
There is only one complex data type, namely object (object), {} curly brackets are used to define an object; objects are surrounded by curly brackets. Inside parentheses, attributes are defined in the form of key-value pairs, such as key : value, also known as attribute name and attribute value. Attributes are separated by commas.
javascript has dynamic typing
var x = 6; // x is a number var x = "Bill"; // x is a string
Special Objects - Arrays
Objects can be composed of one or more attributes (like "collections" in mathematics), when we only need to record the numerical values of grades, another format of objects "arrays ( array)" comes in handy.
1, Array writing method:
Java code Collection code
var scores = [80, 82, 79,]; var courses = [ "Maths", "Chinese", "English"];
2. The value method of the array
Java code Collection code
var course = courses[0]; //Assign course as "Maths"
//The subscript (serial number) of the array starts from zero, so the first item is [ 0], the second is [1],
and so on.
Method 2:
Use the charAt function. For example, to access the second character of the string str, you can use str.charAt(1) to get it.
Here, the parameters of charAt are the same as those in the subscript method, and they are all calculated from 0. .