Copy codeThe Code is as follows:
<! Doctype html>
<Html>
<Head>
<Meta http-equiv = "content-type" content = "text/html; charset = UTF-8">
<Title> javascript data type </title>
</Head>
<Body>
<Script type = "text/javascript">
/**
JavaScript allows
Three basic data types: Numbers, text characters, and boolean values. The number includes the number of characters.
In addition, it supports two small data types: null (null) and undefined (undefined). The two small data types define only one value respectively.
The composite data type-object is also supported. Note that arrays are also an object.
In addition, js also defines a special object called function. Note: A function is also a data type, which is really powerful...
In addition to functions and arrays, the core of the JavaScript language also defines other specialized objects. Example: Date, RegExp, Error ......
*/
/**
Three basic data types
*/
Var $ num = 111;
Var $ str = "aaabbbccc ";
Var $ B = false;
Document. write ("various data types in javascript :");
Document. write ("<br/> $ num type:" + typeof $ num); // number
Document. write ("<br/> $ str type:" + typeof $ str); // string
Document. write ("<br/> $ B type:" + typeof $ B); // boolean
/**
Two types of small data
*/
Var x;
Document. write ("<br/> x Data Type:" + typeof x); // undefined
Var bbb =! X; // true
Document. write ("<br/> bbb data type:" + typeof bbb); // boolean
Document. write ("<br/> two types of small data:" + typeof null + "," + typeof undefined); // object, undefined
/**
Special Data Type: Function
*/
Function myFun (x) {// ...... aaa
Return x * x;
}
Var myFunFun = function (x) {// ...... bbb
Return x * x;
}
Alert (myFun); // aaa
Alert (myFunFun); // bbb
Document. write ("<br/> myFun, myFunFun type:" + typeof myFun + "," + typeof myFunFun); // function, function
/**
Object Data Type. Three methods are as follows:
*/
// Method 1: Create a basic object and add attributes to the object.
Var obj = new Object ();
Obj. name = "yangjiang ";
Obj. sex = "sex ";
// Method 2: using the direct volume of Objects
Var ooo = {};
Ooo. name = "yangjiang ";
Ooo. sex = "sex ";
// Method 3: Define a type (a bit like a class in JAVA): This method is the most commonly used
Function People (name, sex ){
This. name = name;
This. sex = sex;
}
Var oooo = new People ("yangjiang", "sex ");
// The following three output results
Document. write ("<br/> obj type:" + typeof obj); // object
Document. write ("<br/> ooo type:" + typeof ooo); // object
Document. write ("<br/> oooo type:" + typeof oooo); // object
/**
Array is also an object
*/
Var $ array = [];
Var $ arrayA = ["aaa", "bbb", 111, false];
Var $ arrayB = new Array ();
Document. write ("<br/> $ array data type:" + typeof $ array); // object
Document. write ("<br/> $ arrayA data type:" + typeof $ arrayA); // object
Document. write ("<br/> $ arrayB data type:" + typeof $ arrayB); // object
</Script>
</Body>
</Html>