Copy Code code as follows:
<!doctype html>
<meta http-equiv= "Content-type" content= "text/html; Charset=utf-8 ">
<title>javascript Data Type </title>
<body>
<script type= "Text/javascript" >
/**
JavaScript allows to use the
Three basic data types--numbers, text characters, and Boolean values. Where numbers include the number of points.
In addition, it supports two small data types---null (empty) and undefined (undefined), two small data types, each of which defines only one value.
Also supports composite data types--Objects (object), note that arrays are also an object
In addition, JS also defines a special object--functions (function), note: function is a data type, really powerful ...
In addition to functions and arrays, the core of the JavaScript language also defines some of the other specialized objects. For example: Date,regexp,error ...
*/
/**
Three basic types of data
*/
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 kinds of small data types
*/
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 kinds of small data types:" +typeof null+ "," +typeof undefined);//object,undefined
/**
Special data types: Functions
*/
function Myfun (x) {//..............AAA Branch
return x*x;
}
var myfunfun = function (x) {//..............BBB
return x*x;
}
alert (myfun);//AAA Office
alert (myfunfun);//BBB Office
document.write ("Type of <br/>myfun,myfunfun: +typeof myfun+", "+typeof myfunfun");//function,function
/**
Object data type, in the following three ways
*/
The first way: by constructing the base object, adding attributes to the object to achieve
var obj = new Object ();
Obj.name = "Yangjiang";
Obj.sex = "Sex";
The second way: using the direct amount of the object
var ooo = {};
Ooo.name = "Yangjiang";
Ooo.sex = "Sex";
The third Way: Defining a type (somewhat like a class in the Java language): This is the most common method of
function people (Name,sex) {
THIS.name = name;
This.sex = sex;
}
var oooo = new People ("Yangjiang", "sex");
The following output results from three ways
document.write ("Type of <br/>obj:" +typeof obj);//object
document.write ("<br/>ooo type:" +typeof ooo);//object
document.write ("Type of <br/>oooo:" +typeof oooo);//object
/**
An 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>