JS data type

Source: Internet
Author: User
Tags type null

JS is a lightweight, weak type of scripting language.

The variables in JS are loosely typed and can store any data type: Basic structure: var variable name = value;

such as: Var num=12;  var str= ' month falls silent ';  var boo=true; var obj={name: ' Month falls silent '};

var ary=[1,2,3,4];  var reg=/^[0-9]$/; var fn=function () {};

Data types in JS: basic data types and reference data types

Basic data type: consists of simple data segments, including: Number (numeric), string (String), Boolean (True,false), null (NULL), undefined (undefined)

    

Reference data type: composed of complex data, including object data type, functions (function data type)

Object also contains: Object, Math (mathematical method), string (string method), array (array), REGEXP (Regular), date (Time function)

The principle of reference data type: Define a reference data type, first open a new memory address, and then assign a dummy value to the variable (address, a reference to the newly opened memory space)

such as: obj={name: ' AAA '}

Obj.name= ' BBB '; The new memory space is accessed through the virtual memory address, and the value ' AAA ' of the name attribute in the memory space is changed

Data type detection in JS:

typeof detection data type, returns a string representing the data type

Note: Nan is number type undefined is undefined type

Null is an object type null represents null and is an empty pointer

Objects that are commonly used in TypeOf can only return object and cannot be subdivided into specific

Instanceof is used to detect if an instance belongs to a class.

ToString can subdivide object

Constructor structural function detection

JS data type

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.