Get the App
SLTechnology News&Howtos  ›  Development  › 

What are the new data types in es6?

Shulou Source: shulou.com Published: 2022-06-03 19:11:07 10月16日 Update

This article mainly introduces "what are the new data types in es6". In daily operation, I believe many people have doubts about the new data types in es6. The editor consulted all kinds of materials and sorted out simple and easy-to-use methods of operation. I hope it will be helpful to answer the doubts about "what are the new data types in es6?" Next, please follow the editor to study!

The operating environment of this tutorial: windows7 system, ECMAScript version 6, Dell G3 computer.

New data types for ES6

Symbol type (basic)

Set type (complex)

Map type (complex)

WeakSet type (complex)

WeakMap type (complex)

TypedArray type (complex)

Let's take a look at what data types there were before es6.

Basic types:

String

Null

Undefined

Number

Boolean

Type of complexity:

Object

As the new type is basically not used in ordinary work, so the specific introduction or directly look at the professional explanation of MDN, the following to explain some questions often encountered in the interview.

Q1: how do you make an object have a private property? What is the use of Symbol? )

Answer: just use Symbol as the key of the object

{/ / Private scope let a = Symbol () window.oo = {name: 'object', age: 18, [a]: 'this is a private attribute'} console.log (oo [a]) / / this is a private property} / / it can no longer be printed out of scope.

At this point, the object oo has a private property that cannot be printed correctly outside the scope.

Q2: how to quickly repeat an array?

Answer: use Set plus Array.form ()

This is a classic interview question. Before that, let's talk about how to remove repetition before es6:

Let array = [1, 2, 3, 4, 4, 5, 5, 6] ~ function uniq () {let result = [] let hash = {} for (let item0; I

Tags: Types objects data complexity properties methods learning private functions arrays this is associations characters strings that is files articles more questions help Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Microsoft vpn Docker MariaDB Shulou Technology