Detailed explanation of destructuring assignment examples in ES6
This time I bring you a detailed explanation of the destructuring assignment example of ES6. We know that ES6 is very powerful, so this article will give you a good analysis.
Basic usage
let [x, y, ...z] = ['a'] //"a", undefined, []
1. If the right side of the equal sign is not an array, an error will be reported (not a traversable structure)
2. Destructuring assignment var, let,
Const command declarations are applicable
3. The set structure can also be destructured and assigned (it has the Iterator interface, which can be assigned in the form of an array structure)
set destructuring: a collection of single values of any type
let [x, y, z] = new Set(["a", "b", "c"]) x //"a"
Default value
1. The value of the array member is not strictly equal to undefined, and the default value does not take effect (if null, the corresponding value is still null)
[x=1, y=2, z=3, o=4] = ['a', , undefined, null] //"a", 2, 3, null、
2. If the default The value is an expression. The expression is evaluated lazily and will only be executed when used.
3. The default value can refer to other variables assigned to the structure, but the variable must have been Declaration
ObjectStructure assignment
1. The array is arranged in order, and the object variable must have the same name as the attribute
var {bar, foo, baz: loc} = {foo: 'aaa', baz: 'bbb'} bar //undefined foo //"aaa" loc //"bbb" baz //ReferenceError: baz is not defined
2. The variable has been declared before, and an error will be reported when using let assignment
3. Objects that can be used for nested structures
var node = { loc: { start: { line: 1, column: 5 } } } var {loc:{start:{line}}} = node line //1 loc //ReferenceError: loc is not defined start //ReferenceError: start is not defined
line is a variable, loc, start are all patterns
Believe it or not After the above introduction, you have mastered the method. For more exciting information, please pay attention to the php Chinese websiteOther related articles!
Related reading:
Horizontal uninterrupted scrolling effect code
What does the JS engine look like when it is running
How to customize the console object when using JS
The above is the detailed content of Detailed explanation of destructuring assignment examples in ES6. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics











You can easily copy and paste text and files between VMware virtual machines (VMs) and physical systems. This capability allows you to easily transfer images, formatted and unformatted text, and even email attachments between virtual machines and host systems. This article will show you how to enable this feature and demonstrate methods for copying data, files, and folders. How to Enable Copy/Paste in VMware VMware provides three different ways to copy data, files or folders from a virtual machine to a physical computer and vice versa, as explained below: Copy and Paste Elements Drag and Drop Feature Folder Sharing 1 ] Enable copy-paste using VMware Tools You can use the keyboard if your VMWare installation and guest operating system meet the requirements

Want to copy a page in Microsoft Word and keep the formatting intact? This is a smart idea because duplicating pages in Word can be a useful time-saving technique when you want to create multiple copies of a specific document layout or format. This guide will walk you through the step-by-step process of copying pages in Word, whether you are creating a template or copying a specific page in a document. These simple instructions are designed to help you easily recreate your page without having to start from scratch. Why copy pages in Microsoft Word? There are several reasons why copying pages in Word is very beneficial: When you have a document with a specific layout or format that you want to copy. Unlike recreating the entire page from scratch

Windows operating system is one of the most popular operating systems in the world, and its new version Win11 has attracted much attention. In the Win11 system, obtaining administrator rights is an important operation. Administrator rights allow users to perform more operations and settings on the system. This article will introduce in detail how to obtain administrator permissions in Win11 system and how to effectively manage permissions. In the Win11 system, administrator rights are divided into two types: local administrator and domain administrator. A local administrator has full administrative rights to the local computer

Detailed explanation of division operation in OracleSQL In OracleSQL, division operation is a common and important mathematical operation, used to calculate the result of dividing two numbers. Division is often used in database queries, so understanding the division operation and its usage in OracleSQL is one of the essential skills for database developers. This article will discuss the relevant knowledge of division operations in OracleSQL in detail and provide specific code examples for readers' reference. 1. Division operation in OracleSQL

Detailed explanation of Linux system call system() function System call is a very important part of the Linux operating system. It provides a way to interact with the system kernel. Among them, the system() function is one of the commonly used system call functions. This article will introduce the use of the system() function in detail and provide corresponding code examples. Basic Concepts of System Calls System calls are a way for user programs to interact with the operating system kernel. User programs request the operating system by calling system call functions

The modulo operator (%) in PHP is used to obtain the remainder of the division of two numbers. In this article, we will discuss the role and usage of the modulo operator in detail, and provide specific code examples to help readers better understand. 1. The role of the modulo operator In mathematics, when we divide an integer by another integer, we get a quotient and a remainder. For example, when we divide 10 by 3, the quotient is 3 and the remainder is 1. The modulo operator is used to obtain this remainder. 2. Usage of the modulo operator In PHP, use the % symbol to represent the modulus

On Mac, it's common to need to copy and paste content between different documents. The macOS clipboard only retains the last copied item, which limits our work efficiency. Fortunately, there are some third-party applications that can help us view and manage our clipboard history easily. How to View Clipboard Contents in Finder There is a built-in clipboard viewer in Finder, allowing you to view the contents of the current clipboard at any time to avoid pasting errors. The operation is very simple: open the Finder, click the Edit menu, and then select Show Clipboard. Although the function of viewing the contents of the clipboard in the Finder is small, there are a few points to note: the clipboard viewer in the Finder can only display the contents and cannot edit them. If you copied

Detailed explanation of Linux's curl command Summary: curl is a powerful command line tool used for data communication with the server. This article will introduce the basic usage of the curl command and provide actual code examples to help readers better understand and apply the command. 1. What is curl? curl is a command line tool used to send and receive various network requests. It supports multiple protocols, such as HTTP, FTP, TELNET, etc., and provides rich functions, such as file upload, file download, data transmission, proxy
