JavaScript data types

Source: Internet
Author: User

Basic data type:

Number,boolean,string,undefined,null reference types: object,array,function, Difference: Reference types can add properties and methods, and primitive types cannot typeof operators: typeof is the best tool to determine whether a variable is a string, a numeric value, a Boolean, or a undefined undefined value is undefined Boolean is a Boolean string that is a number The value function is either an object or a null

Basic data Type 1, number contains integer and floating-point number two values NaN: non-numeric type; features: any operation related to Nan will return Nan nan not equal to itself IsNaN () function: used to detect whether a non-numeric type
1 IsNaN (111)   //true           2 IsNaN ("HHHH")       //false

2, Boolean True and false two value true does not necessarily =1,false not necessarily =0 Boolean () function: Convert to TRUE or false any non-empty string, any non-0 value, any non-empty object will be converted to true empty string, 0 and N An,null and undefined are converted to FALSE3, string strings have the. Length property, which returns the length of the string once the string is created, its value cannot be changed, and the original string conversion must be destroyed to change: string () applies to any class Type of data
1 var x=123;2 var y=string (x)

ToString () null and undefined do not have this method
var x=123var y=x.tostring ()

  

4, NULL logically NULL represents a pointer to an empty object, typeof detection returns UNDEFINED5, undefined uses VAR to declare the variable, but the variable is not initialized with a value, typeof detects a relationship that returns object undefined and null:  Undefined is derived from null, so using the "= =" Comparison will return true if it is not necessary to declare the variable as undefined while declaring an empty object should have its value assigned to a NULL difference: null means "no object" i.e. there should be no value at that place Undefined means "missing value", that is, there should be a value here, but there is not a collection of reference type 1, object set of data and features most of the reference type values are instances of object, so the base of an instance of object is the object type, in other words, Any properties and methods that the object type has also exist in more specific objects.

Created by: 1, var o=new object () 2, using object literal notation
1 var o={2  3}

2, Array creation method: 1, using the array constructor
1 var color=new Array ("Red", "blue", "yellow")

2. Use array literal notation:
1 var color=["Red", "blue", "yellow"]

3. Functions Each function is an instance of type function, and is created with properties and methods like other reference types: 1, static method function name ([virtual argument list]) {function body [return[function]      return value;]]    } 2, dynamic anonymous method var function name =new function (["Virtual argument list"], "function body");      3, Direct volume method function name =function ([virtual argument list]) {function body; } JS basic data types and reference data types memory allocation problems (heap and stack) basic data types are generally stored in the stack, these types in memory occupy a fixed amount of space, their values are stored in the stack space reference type is the size of the type is not fixed, but their address size is fixed, so the address is stored in the stack, The value stored in the heap is destroyed at the end of the current execution environment, and the reference type is not destroyed with the execution environment, and the object is reclaimed by the garbage collection mechanism only if all variables referencing it are not present.

JavaScript data types

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.