Javascript Data Types in the study notes of javascript authoritative guide

Source: Internet
Author: User

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>

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.