js data classification

Table of contents

Article directory

foreword

1. Simple data types/basic types

1.Number digital type

2. String string type

3. Boolean Boolean value type

4.null

Extension: Why is null an object?

5.undefined

6.symbol

2. Complex data types/reference types/object types

1 built-in object

2 host object

3 custom objects

Three Object Extensions: Classification of Attributes and Methods

One: attributes

1 custom attribute (own property)

2 Inherited property

Two: method

1 static method

2 Prototype methods

Summarize



foreword

发现很多小伙伴对js数据类型不是很理解,在本篇文章特别进行了整理分类。


提示:以下是本篇文章正文内容,下面案例可供参考

1. Simple data types/basic types

Simple types are also called basic data types or value types. Put the value itself directly on the stack

1.Number digital type

Contains integer and floating point values ​​Example: 1 0.1

2. String string type

For example: 'Zhang San'

3. Boolean Boolean value type

true、false

4.null

Represents null, is a null pointer

Extension: Why is null an object?

Null: According to the principle that everything is an object, null is an object, but the reason why null (not an object) is judged to be an object type is that "in the initial version of JS, a 32-bit system was used, and the type information of low-order storage variables was used for performance considerations. , the beginning of 000 means an object, but null means all zeros, so it is wrongly judged as an object. Although the current internal type judgment code has changed, this bug has been handed down.

5.undefined

When a variable is declared unassigned, the variable is assigned the value undefined.

6.symbol

ES6 new data type. represents a unique value

2. Complex data types/reference types/object types

Complex types, also called reference types, are placed in the heap first at the stack memory address and then this address points to the data in the heap

1 built-in object

Common built-in objects:

  • String(string object);
  • Array(array object);
  • Date(date object);
  • Math(mathematical object);
  • Number(number object);
  • Function(function object);

2 host object

  • BOM - Browser Object Model;
  • DOM - Document Object Model;

3 custom objects

The first is a custom object in the form of Object

        var variable name=new Object();//object instance (empty object)

The second is a custom object in the form of { } curly braces

Three Object Extensions: Classification of Attributes and Methods

Objects are inseparable from attributes and methods, so what are the types of attributes and methods?

One: attributes

1 custom attribute (own property)

are properties defined directly on the object.

2 Inherited property

is a property defined in the object's prototype object

Two: method

1 static method

This in the static method points to the object that calls it, and the static method can only be called by the class

2 Prototype methods

This in the prototype method points to the instance object, and the prototype method can only be called by the instance


Summarize

Reference type values ​​can add properties and methods, while primitive type values ​​cannot.

The fundamental difference is the storage method in memory, the reference type is stored in the stack, and the basic type is stored in the heap

Guess you like

Origin blog.csdn.net/wanjun_007/article/details/126754303