Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What are the data types of es6

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

In this article, the editor introduces in detail "what are the data types of es6", the content is detailed, the steps are clear, and the details are handled properly. I hope that this article "what are the data types of es6" can help you solve your doubts.

There are seven es6 data types, namely: 1, Boolean is a Boolean type; 2, Null is an empty type; 3, Undefined is an unassigned type; 4, Number is a numeric type; 5, String is a string type; 6, Symbol is a unique type; 7, Object is an object type.

This article operating environment: windows10 system, Vue2.9.6 version, DELL G3 computer.

What are the es6 data types

Es6t defines seven data types: six raw data types and one object type.

They are:

Boolean

Null

Undefined

Number

String

Symbol

Object

Detailed introduction:

1. A value data type: null, undefined

Custom variables do not need to be defined as undefined, but not for null, that is, as long as you intend to save the object but do not really save the object, you should explicitly let the variable hold the null value.

It mainly summarizes the similarities and differences between the two.

What they have in common: both are data types of the same value; both return false; when they participate in the judgment. Neither has a method.

Differences: (a), null is an object, but undefined is not an object; (b), null is a keyword, undefined is not a keyword; (c), null is 0 when converted to a number, while undefined is converted to a number is NaN; (d), typeof null returns' object',typeof undefined return 'undefined'

Alert (null = = undefined); / / true

2. The data type of the two values: boolean, namely true and false

The main purpose is to judge

Normally, only these six cases will be converted to false: empty string, null, undefined, 0,-0, NaN

There are two ways to convert an array to a Boolean value: Boolean (),! ()

3. The data type of the three values: number, namely integer, floating point number, NaN (personal classification, not important).

When using number, it is recommended to use decimal as much as possible, less hexadecimal, not octal.

Do not compare data when using floating-point numbers. 0.1-0.2 do not compare with 0.3. The reason is that the computer uses binary to represent data, and the binary representation of 0.1 plus 0.2 is not equal to the binary representation of 0.3.

There is a strange work in number, which is not equal in itself. That is alert (NaN = = NaN) / / false

But NaN is a data type, which means that the return value of typeof NaN is' number'

For the above two features, ECMAScript provides a function isNaN (); the purpose is to determine whether the incoming value can be converted to a number, and the return value is a Boolean value.

The conversion of an empty string to a number is 0

You can use Number () to convert a value to a numeric type

4. String string

Strings are generally represented by double quotation marks or single quotation marks, and it is recommended to use single quotation marks to represent the string.

The characteristics of the string: the string in ECMAScript is immutable, that is, once the string is created, its value will not be changed, if you change the value of the string, first destroy the original string, and then populate the variable with a string containing the new value.

There are two ways to convert a value to a string type, one is to call the toString () method, and the other is to String ()

Note: null and undefined do not have a toString () method.

5 、 Symbol

There are two values for Symbol. One is the original attribute name. One is to have an attribute name generated by Symbol (), which does not conflict because its representation is unique.

Note when using Symbol: you cannot use the new operator before the Symbol function (Symbol is a primitive data type, not an object); you cannot add methods to Symbol; symbol is a basic data type in the form of a class string; and symbol can be converted to a string (two ways, which have been described earlier. Can be converted to boolean, but not to Number

It is best to pass parameters when using Symbol (). If you do not pass parameters, you will return 'symbol' when you use typeof, which is easy to distinguish. Because the value of symbol is unique, even if the same parameter is passed, the values of the two are not the same.

Because the value of Symbol is unique, it can exist as an attribute name, but as an attribute name, you cannot do a dot (.) Operation, all symbol values are placed in square brackets ([]).

After reading this, the article "what are the data types of es6" has been introduced. If you want to master the knowledge points of this article, you still need to practice and use it yourself to understand it. If you want to know more about related articles, welcome to follow the industry information channel.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report