Five types of data in JavaScript

Source: Internet
Author: User

    • Undefined

Not defined. Only one value undefined

    • Null

Only one value, NULL

    • Boolean

In JavaScript, it is true as long as the logical expression does not return undefined and does not return NULL.

if (3) True

if (null) false

if (undefined) false

    • Number

    • String
There is no char type in JavaScript.

The string definition can be in single or double quotes.

<HTML> <Head> <Scripttype= "Text/javascript"> //var s= "Hello";//alert (typeof s);//s is a string typevars=NewString ("Hello");//S is the object typeAlert (typeofs); </Script> </Head>         <Body> </Body> </HTML>
    • typeof is a unary operator used to obtain the data type of a variable

Its return value has five undefined,boolean,number,string and an object.

The first four of them are well understood. And the last object is not to be judged by the programmer, only the general return of the object

    • In JavaScript, if the function does not declare a return value, undefined is returned by default.

If the return value is declared, then what is actually returned is what.

    • Undefined is derived from null, so the comparison returns true

alert (undefined==null);//true

    • Forcing type conversions

In JavaScript, there are three types of coercion conversions:

Boolean (value)

Number (value)

String (value)

<HTML> <Head> <Scripttype= "Text/javascript"> varNum=Number (3); alert (num);vars="Hello"; alert (Boolean (s));varS1=String ("Hello"); Alert (typeofs1);varobj=NewString ("Hello");//This is not mandatory type conversion! Alert (typeofobj); </Script> </Head>         <Body> </Body> </HTML>

In JavaScript, all objects are inherited from object objects.

Generated in new way.

JS some of the methods can be enumerated, and some are not.

The JS built-in method can be used to determine whether it can be enumerated.

<HTML> <Head> <Scripttype= "Text/javascript"> varObject=NewObject (); for(varvinchobject) {Console.log (v);} Alert (object.propertyisenumerable ("prototype"));//returns FALSE, indicating that there are no properties that can be enumerated, and that the corresponding properties of the child objects are also not enumerated</Script> </Head>         <Body> </Body></HTML>

Enumerate the properties of a custom type

<HTML> <Head> <Scripttype= "Text/javascript"> varmember=function(name,age) { This. Name=name;  This. Age=Age ;} varm=NewMember ("Liudh", -); for(varvinchm)     {Console.log (v); //name    // Age} alert (M.propertyisenumerable ("prototype"));//false//For (Var v in window) {//Console.log (v);//}</Script> </Head>         <Body> </Body> </HTML>

Five types of data in JavaScript

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.