Was this page helpful?
Variable Declaration
let and const are two relatively new concepts for variable declarations in JavaScript. As we mentioned earlier , let is similar to var in some respects, but allows users to avoid some of the common “gotchas” that users run into in JavaScript.
const is an augmentation of let in that it prevents re-assignment to a variable.
With TypeScript being an extension of JavaScript, the language naturally supports let and const . Here we’ll elaborate more on these new declarations and why they’re preferable to var .
If you’ve used JavaScript offhandedly, the next section might be a good way to refresh your memory. If you’re intimately familiar with all the quirks of var declarations in JavaScript, you might find it easier to skip ahead.
var declarations
Declaring a variable in JavaScript has always traditionally been done with the var keyword.
As you might’ve figured out, we just declared a variable named a with the value 10 .
We can also declare a variable inside of a function:
and we can also access those same variables within other functions:
In this above example, g captured the variable a declared in f . At any point that g gets called, the value of a will be tied to the value of a in f . Even if g is called once f is done running, it will be able to access and modify a .
Scoping rules
var declarations have some odd scoping rules for those used to other languages. Take the following example:
Some readers might do a double-take at this example. The variable x was declared within the if block , and yet we were able to access it from outside that block. That’s because var declarations are accessible anywhere within their containing function, module, namespace, or global scope - all which we’ll go over later on - regardless of the containing block. Some people call this var -scoping or function-scoping . Parameters are also function scoped.
These scoping rules can cause several types of mistakes. One problem they exacerbate is the fact that it is not an error to declare the same variable multiple times:
Maybe it was easy to spot out for some experienced JavaScript developers, but the inner for -loop will accidentally overwrite the variable i because i refers to the same function-scoped variable. As experienced developers know by now, similar sorts of bugs slip through code reviews and can be an endless source of frustration.
Variable capturing quirks
Take a quick second to guess what the output of the following snippet is:
For those unfamiliar, setTimeout will try to execute a function after a certain number of milliseconds (though waiting for anything else to stop running).
Ready? Take a look:
Many JavaScript developers are intimately familiar with this behavior, but if you’re surprised, you’re certainly not alone. Most people expect the output to be
Remember what we mentioned earlier about variable capturing? Every function expression we pass to setTimeout actually refers to the same i from the same scope.
Let’s take a minute to consider what that means. setTimeout will run a function after some number of milliseconds, but only after the for loop has stopped executing; By the time the for loop has stopped executing, the value of i is 10 . So each time the given function gets called, it will print out 10 !
A common work around is to use an IIFE - an Immediately Invoked Function Expression - to capture i at each iteration:
This odd-looking pattern is actually pretty common. The i in the parameter list actually shadows the i declared in the for loop, but since we named them the same, we didn’t have to modify the loop body too much.
let declarations
By now you’ve figured out that var has some problems, which is precisely why let statements were introduced. Apart from the keyword used, let statements are written the same way var statements are.
The key difference is not in the syntax, but in the semantics, which we’ll now dive into.
Block-scoping
When a variable is declared using let , it uses what some call lexical-scoping or block-scoping . Unlike variables declared with var whose scopes leak out to their containing function, block-scoped variables are not visible outside of their nearest containing block or for -loop.
Here, we have two local variables a and b . a ’s scope is limited to the body of f while b ’s scope is limited to the containing if statement’s block.
Variables declared in a catch clause also have similar scoping rules.
Another property of block-scoped variables is that they can’t be read or written to before they’re actually declared. While these variables are “present” throughout their scope, all points up until their declaration are part of their temporal dead zone . This is just a sophisticated way of saying you can’t access them before the let statement, and luckily TypeScript will let you know that.
Something to note is that you can still capture a block-scoped variable before it’s declared. The only catch is that it’s illegal to call that function before the declaration. If targeting ES2015, a modern runtime will throw an error; however, right now TypeScript is permissive and won’t report this as an error.
For more information on temporal dead zones, see relevant content on the Mozilla Developer Network .
Re-declarations and Shadowing
With var declarations, we mentioned that it didn’t matter how many times you declared your variables; you just got one.
In the above example, all declarations of x actually refer to the same x , and this is perfectly valid. This often ends up being a source of bugs. Thankfully, let declarations are not as forgiving.
The variables don’t necessarily need to both be block-scoped for TypeScript to tell us that there’s a problem.
That’s not to say that a block-scoped variable can never be declared with a function-scoped variable. The block-scoped variable just needs to be declared within a distinctly different block.
The act of introducing a new name in a more nested scope is called shadowing . It is a bit of a double-edged sword in that it can introduce certain bugs on its own in the event of accidental shadowing, while also preventing certain bugs. For instance, imagine we had written our earlier sumMatrix function using let variables.
This version of the loop will actually perform the summation correctly because the inner loop’s i shadows i from the outer loop.
Shadowing should usually be avoided in the interest of writing clearer code. While there are some scenarios where it may be fitting to take advantage of it, you should use your best judgement.
Block-scoped variable capturing
When we first touched on the idea of variable capturing with var declaration, we briefly went into how variables act once captured. To give a better intuition of this, each time a scope is run, it creates an “environment” of variables. That environment and its captured variables can exist even after everything within its scope has finished executing.
Because we’ve captured city from within its environment, we’re still able to access it despite the fact that the if block finished executing.
Recall that with our earlier setTimeout example, we ended up needing to use an IIFE to capture the state of a variable for every iteration of the for loop. In effect, what we were doing was creating a new variable environment for our captured variables. That was a bit of a pain, but luckily, you’ll never have to do that again in TypeScript.
let declarations have drastically different behavior when declared as part of a loop. Rather than just introducing a new environment to the loop itself, these declarations sort of create a new scope per iteration . Since this is what we were doing anyway with our IIFE, we can change our old setTimeout example to just use a let declaration.
and as expected, this will print out
const declarations
const declarations are another way of declaring variables.
They are like let declarations but, as their name implies, their value cannot be changed once they are bound. In other words, they have the same scoping rules as let , but you can’t re-assign to them.
This should not be confused with the idea that the values they refer to are immutable .
Unless you take specific measures to avoid it, the internal state of a const variable is still modifiable. Fortunately, TypeScript allows you to specify that members of an object are readonly . The chapter on Interfaces has the details.
let vs. const
Given that we have two types of declarations with similar scoping semantics, it’s natural to find ourselves asking which one to use. Like most broad questions, the answer is: it depends.
Applying the principle of least privilege , all declarations other than those you plan to modify should use const . The rationale is that if a variable didn’t need to get written to, others working on the same codebase shouldn’t automatically be able to write to the object, and will need to consider whether they really need to reassign to the variable. Using const also makes code more predictable when reasoning about flow of data.
Use your best judgement, and if applicable, consult the matter with the rest of your team.
The majority of this handbook uses let declarations.
Destructuring
Another ECMAScript 2015 feature that TypeScript has is destructuring. For a complete reference, see the article on the Mozilla Developer Network . In this section, we’ll give a short overview.
Array destructuring
The simplest form of destructuring is array destructuring assignment:
This creates two new variables named first and second . This is equivalent to using indexing, but is much more convenient:
Destructuring works with already-declared variables as well:
And with parameters to a function:
You can create a variable for the remaining items in a list using the syntax ... :
Of course, since this is JavaScript, you can just ignore trailing elements you don’t care about:
Or other elements:
Tuple destructuring
Tuples may be destructured like arrays; the destructuring variables get the types of the corresponding tuple elements:
It’s an error to destructure a tuple beyond the range of its elements:
As with arrays, you can destructure the rest of the tuple with ... , to get a shorter tuple:
Or ignore trailing elements, or other elements:
Object destructuring
You can also destructure objects:
This creates new variables a and b from o.a and o.b . Notice that you can skip c if you don’t need it.
Like array destructuring, you can have assignment without declaration:
Notice that we had to surround this statement with parentheses. JavaScript normally parses a { as the start of block.
You can create a variable for the remaining items in an object using the syntax ... :
Property renaming
You can also give different names to properties:
Here the syntax starts to get confusing. You can read a: newName1 as ” a as newName1 ”. The direction is left-to-right, as if you had written:
Confusingly, the colon here does not indicate the type. The type, if you specify it, still needs to be written after the entire destructuring:
Default values
Default values let you specify a default value in case a property is undefined:
In this example the b? indicates that b is optional, so it may be undefined . keepWholeObject now has a variable for wholeObject as well as the properties a and b , even if b is undefined.
Function declarations
Destructuring also works in function declarations. For simple cases this is straightforward:
But specifying defaults is more common for parameters, and getting defaults right with destructuring can be tricky. First of all, you need to remember to put the pattern before the default value.
The snippet above is an example of type inference, explained earlier in the handbook.
Then, you need to remember to give a default for optional properties on the destructured property instead of the main initializer. Remember that C was defined with b optional:
Use destructuring with care. As the previous example demonstrates, anything but the simplest destructuring expression is confusing. This is especially true with deeply nested destructuring, which gets really hard to understand even without piling on renaming, default values, and type annotations. Try to keep destructuring expressions small and simple. You can always write the assignments that destructuring would generate yourself.
The spread operator is the opposite of destructuring. It allows you to spread an array into another array, or an object into another object. For example:
This gives bothPlus the value [0, 1, 2, 3, 4, 5] . Spreading creates a shallow copy of first and second . They are not changed by the spread.
You can also spread objects:
Now search is { food: "rich", price: "$$", ambiance: "noisy" } . Object spreading is more complex than array spreading. Like array spreading, it proceeds from left-to-right, but the result is still an object. This means that properties that come later in the spread object overwrite properties that come earlier. So if we modify the previous example to spread at the end:
Then the food property in defaults overwrites food: "rich" , which is not what we want in this case.
Object spread also has a couple of other surprising limits. First, it only includes an objects’ own, enumerable properties . Basically, that means you lose methods when you spread instances of an object:
Second, the TypeScript compiler doesn’t allow spreads of type parameters from generic functions. That feature is expected in future versions of the language.
using declarations
using declarations are an upcoming feature for JavaScript that are part of the Stage 3 Explicit Resource Management proposal. A using declaration is much like a const declaration, except that it couples the lifetime of the value bound to the declaration with the scope of the variable.
When control exits the block containing a using declaration, the [Symbol.dispose]() method of the declared value is executed, which allows that value to perform cleanup:
At runtime, this has an effect roughly equivalent to the following:
using declarations are extremely useful for avoiding memory leaks when working with JavaScript objects that hold on to native references like file handles
or scoped operations like tracing
Unlike var , let , and const , using declarations do not support destructuring.
null and undefined
It’s important to note that the value can be null or undefined , in which case nothing is disposed at the end of the block:
which is roughly equivalent to:
This allows you to conditionally acquire resources when declaring a using declaration without the need for complex branching or repetition.
Defining a disposable resource
You can indicate the classes or objects you produce are disposable by implementing the Disposable interface:
await using declarations
Some resources or operations may have cleanup that needs to be performed asynchronously. To accommodate this, the Explicit Resource Management proposal also introduces the await using declaration:
An await using declaration invokes, and awaits , its value’s [Symbol.asyncDispose]() method as control leaves the containing block. This allows for asynchronous cleanup, such as a database transaction performing a rollback or commit, or a file stream flushing any pending writes to storage before it is closed.
As with await , await using can only be used in an async function or method, or at the top level of a module.
Defining an asynchronously disposable resource
Just as using relies on objects that are Disposable , an await using relies on objects that are AsyncDisposable :
await using vs await
The await keyword that is part of the await using declaration only indicates that the disposal of the resource is await -ed. It does not await the value itself:
await using and return
It’s important to note that there is a small caveat with this behavior if you are using an await using declaration in an async function that returns a Promise without first await -ing it:
Because the returned promise isn’t await -ed, it’s possible that the JavaScript runtime may report an unhandled rejection since execution pauses while await -ing the asynchronous disposal of x , without having subscribed to the returned promise. This is not a problem that is unique to await using , however, as this can also occur in an async function that uses try..finally :
To avoid this situation, it is recommended that you await your return value if it may be a Promise :
using and await using in for and for..of statements
Both using and await using can be used in a for statement:
In this case, the lifetime of x is scoped to the entire for statement and is only disposed when control leaves the loop due to break , return , throw , or when the loop condition is false.
In addition to for statements, both declarations can also be used in for..of statements:
Here, x is disposed at the end of each iteration of the loop , and is then reinitialized with the next value. This is especially useful when consuming resources produced one at a time by a generator.
using and await using in older runtimes
using and await using declarations can be used when targeting older ECMAScript editions as long as you are using a compatible polyfill for Symbol.dispose / Symbol.asyncDispose , such as the one provided by default in recent editions of NodeJS.
The TypeScript docs are an open source project. Help us improve these pages by sending a Pull Request ❤
Last updated: Dec 23, 2024
Harness The Power Of Destructuring With TypeScript: From Beginner To Mastery
The Destructuring Assignment is one of these aha moments you have as a software engineer.
After spending your life trying to read values from arrays or objects, you discover the syntax that changes your life. Forever.
This article will teach you the basics of destructuring arrays and objects. I have collected some useful tips on how to set default values and how to use aliases. We will also learn how to integrate types in TypeScript.
It wasn’t a straightforward process for me, but I have to say it made sense after all. 🤓
If you’re new to JavaScript or TypeScript, this article will help you understand many of the things that are happening in the code. It’s a feature that is highly used in every project.
Apfelkunchen? 🍰
Destructuring Objects
To explain how destructuring works, consider the following object structure that hosts application settings:
We could write a React component to display the values to the user:
Not a big fan of React? Well, it’s not important for this example. You can simply imagine that this function will output HTML markup for us.
Let’s focus on the first 3 lines within our function.
This initialization could become extremely useful when we are consuming values multiple times within the scope of a function or a method. It’s better if you have to type push instead of the complete path settings.user.notifications.push .
Yes, I know.
IDEs are our friends. They could make code completion very easy for us. But such verbosity will make your code harder to read.
So, what are you telling me Nicos? Do I have to instantiate the values for all these properties? In every single function that I’m writing? That’s nonsense!
You should strive to declare the variables, but not all of them, just the ones you are consuming. And the destructuring operator makes the whole process much easier for you.
Here’s how we could destructure the updates property from the settings object:
And that was it!
In this example, we have just created a constant updates , which is a copy of the settings counter. And I’m highlighting the word copy here, because if you remember literal values are being copied, reference values are not. The same doesn’t apply if you try to destructure an object value.
Now, what if I wanted to access a nested value?
Here’s what we could try:
If this is a new concept for you, it may take you some time to read and understand. Take your time. All we’re doing here is to use the same logic that we use to define an object structure, but instead of creating an object, we are declaring constants that host the values of the settings object properties that we select.
The previous example will produce the following constants: updates , volume , and push .
It’s important to note here, that the system , user , and notifications are not going to be declared. The compiler will use them as a map to understand from where it will retrieve the values they encapsulate.
And that’s it! We can now replace the previous code in our function:
Now someone will argue if this is actually less code than we used to have before. And I would agree with you that this produces more lines of code than we had. But we don’t repeat ourselves. If we want to display, let’s say for example the brightness level, all we have to do is to destructure its property name:
It’s much easier to work with this component.
Since these are actual variables, our text editor will let us know if some of the variables are not being used anymore.
Setting default values
The destructuring operator allows us to specify default values, in case there are no values set.
For that, we use the = operator:
Here we are setting that the updates should have a default value = 0 , the volume = 0.3 , and the push notifications must be false by default.
Another cool feature is that we could rename the properties. This is needed in many cases. For example, you may have another variable in that scope which already uses that name updates . This conflict will reduce compiler errors in TypeScript, or it will silently fail in JavaScript.
Here’s how we can set a custom name, aka alias :
This is equivalent to the following:
How to add types?
Now, the tricky part is that the syntax is pretty much the same as the one TypeScript uses to declare the types.
Because of that, we need to define types in a separate object structure, following the initial destructuring object:
This is cumbersome on multiple levels:
- To destructure the value settings.updates you must get it from the updatesCounter constant. It’s like an alias for the updates property.
- The constant updates is not going to be declared, which lets you use it in that scope for something else.
- The type declaration is defined in a second object structure, right after the first one. For this object structure we are using the initial name of the property updates , and not the alias updatesCounter .
And that’s it! Basically now you are able to use the destructuring operator with any object type, you know how to define types for it, how to set default values, and how to use aliases for it’s property names.
Now try it by yourself!
Can you add types to the following code?
You will find the solution at the end of the article.
One last tip: We could move the destructuring operator in the function parameters:
This is a bit trickier to read, especially if you are new to destructuring objects. But it’s actually simpler if you get used to it. Many developers prefer this way for writing React components.
As an exercise, you can try to write types for these React component constants. You will find the answer at the end of this post.
Destructuring arrays
Destructuring works perfectly with arrays.
Now, arrays don’t exactly have named properties, like objects do:
We can only store their indexed values with a more friendly name:
Here’s how you can use destructuring to get the same result:
Note that we use [] brackets instead of {} object literals.
Also, we don’t care about how many elements an array has. We are only storing the first two items.
This code is equivalent to the following:
Comparing these two approaches, we could see that the first one is much simpler to read and more compact.
Similar to how we declare types for object destructuring, we could specify the types of our variables right after their declaration:
We can also skip items that we don’t want:
Here, we are getting only the first and the third items.
We can also skip the first item:
This will only give us the third item.
Default values
Of course, default items are also supported:
The first item will get the item of an empty string, if it’s undefined or null . For example, when the array is empty.
Pretty practical, right? 😎
Ah, and one more tip.
This becomes quite useful when you combine it with functions:
The solution
Here’s how we could declare types for our destructured constants:
We can increase readability by separating the types to an interface:
And this is the most common way to specify props for our React components in TypeScript projects.
Cover artwork by Pawel Czerwinski . The artwork within the article is created by Milad Fakurian .
Understanding TypeScript Destructuring Assignment with Type
TypeScript Destructuring Assignment with Type
Destructuring assignment is a powerful feature in TypeScript that allows you to extract values from objects or arrays and bind them to variables. When combined with type annotations, TypeScript destructuring becomes even more robust and expressive.
Basics of Destructuring Assignment
In TypeScript, destructuring assignment follows a simple syntax using curly braces for objects and square brackets for arrays. Let's look at a basic example:
Destructuring with Type Annotations
By adding type annotations to destructuring assignments, you can provide type information to the variables being assigned. This helps in improving code readability and catching potential errors at compile time. Consider the following example:
Nested Destructuring with Type
TypeScript allows you to destructure nested objects or arrays while specifying types for each level of nesting. Let's see how this can be done:
TypeScript destructuring assignment with type brings a new level of clarity and type safety to your code. By leveraging type annotations in destructuring assignments, you can write cleaner and more maintainable code. Experiment with different scenarios and explore the flexibility of TypeScript's destructuring capabilities in your projects.
Mastering TypeScript with RxJS: A Comprehensive Guide
Explore the power of TypeScript and RxJS for reactive programming
Typescript Tips: Destructuring Assignments
Typescript has become my favorite language to use during web development. Most of all, I love the type safety. However, there are so many features to the language it's easy for little useful tidbits to get forgotten about. I'm going to be writing some brief posts on some little features that have really been helpful during web development.
The first of these is destructuring assignments.
Destructuring Arrays
For example:
While this is a trivial example, the opritunity here is to assign multiple values from an array at once. This would be an alternative to this;
It simplifies and reduces the amount of code.
Destructuring Objects
While it's useful for arrays in certain circumstances, it really shines with objects.
This becomes even more useful in the case of functional react components, and in functions when an object is passed in and just a few values are needed.
While the examples are very contrived, they just show the main idea.
Capturing Remaining Arguments
While I had known about destructuring assignments for a while, there was a little tidbit that I missed. That was capturing the remaining arguments. For example, in our previous example with arrays:
one will be "one", and remaining will be ["two", "three"] . And likewise with objects.
In this case, remaining is an object that contains lastName, address, phoneNumber (the remaining properties from the person object)
Wrapping Up
While it's not something that I will always use, destructuring assignments can tidy up code. In certain contexts such as React development the end up being used very frequently.
I hope you find this tidbit useful. Until the next tidbit, happy coding!
DEV Community
Posted on Dec 15, 2022
Destructuring Assignment is a Typescript
Destructuring TypeScript supports the following forms of Destructuring (literally named after de-structuring i.e. breaking up the structure): 1. Object Destructuring 2. Array Destructuring It is easy to think of destructuring as an inverse of structuring. The method of structuring in JavaScript is the object literal:
Without the awesome structuring support built into JavaScript, creating new objects on the fly would indeed be very cumbersome. Destructuring brings the same level of convenience to getting data out of a structure. Object Destructuring Destructuring is useful because it allows you to do in a single line, what would otherwise require multiple lines. Consider the following case:
// Destructuring assignment
Here in the absence of destructuring you would have to pick off x,y,width,height one by one from rect. To assign an extracted variable to a new variable name you can do the following: // structure
// destructure
Additionally you can get deep data out of a structure using destructuring. This is shown in the following example:
Effectively
Object Destructuring with rest You can pick up any number of elements from an object and get an object of the remaining elements using object destructuring with rest.
A common use case is also to ignore certain properties. For example: // Example function
// Imagine some code that might break // if you pass in an object // with more items than desired } // Some point you get from somewhere
/** A nifty use of rest to remove extra properties */
Array Destructuring A common programming question: "How to swap two variables without using a third one?". The TypeScript solution:
Note that array destructuring is effectively the compiler doing the [0], [1], ... and so on for you. There is no guarantee that these values will exist. Array Destructuring with rest You can pick up any number of elements from an array and get an array of the remaining elements using array destructuring with rest.
Array Destructuring with ignores You can ignore any index by simply leaving its location empty i.e. , , in the left hand side of the assignment. For example:
JS Generation The JavaScript generation for non ES6 targets simply involves creating temporary variables, just like you would have to do yourself without native language support for destructuring e.g.
// becomes //
Summary Destructuring can make your code more readable and maintainable by reducing the line count and making the intent clear. Array destructuring can allow you to use arrays as though they were tuples Please give a like and follow,if you like my work
Top comments (2)
Templates let you quickly answer FAQs or store snippets for re-use.
- Location Kolkata
- Work Senior Software Developer @Capital Numbers
- Joined Mar 9, 2021
@javascriptcoff1
@programazing
Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink .
Hide child comments as well
For further actions, you may consider blocking this person and/or reporting abuse
How to Become a Java Developer in 2025
Kaja Uvais - Dec 22
Update Front-end Dev.to Challenge
Hanzla Baig - Dec 21
TypeScript vs JavaScript: Key Differences, Features, and When to Use Each
Sarthak Niranjan - Dec 22
Day 21: In the name of Progress! 📈
Valeria - Dec 21
We're a place where coders share, stay up-to-date and grow their careers.
IMAGES
COMMENTS
The is code works fine by destructuring the object and assigning the variables, const { allowNegative, decimal, precision, prefix, suffix, thousands } = this.options; But when i try with this operator like below it throws an error:
Destructuring. Another ECMAScript 2015 feature that TypeScript has is destructuring. For a complete reference, see the article on the Mozilla Developer Network. In this section, we’ll give a short overview. Array destructuring. The simplest form of destructuring is array destructuring assignment:
Dec 21, 2023 · As TypeScript developers, we occasionally face perplexing issues with object destructuring assignments. Here, we dissect these problems and offer practical solutions. A common scenario involves…
Oct 25, 2024 · TypeScript destructuring assignment is a powerful feature that simplifies the process of extracting values from complex data structures. By mastering destructuring, you can write cleaner and more concise code, improving the readability and maintainability of your TypeScript projects.
Apr 15, 2019 · The correct way to handle TypeScript functional destructuring is to define an interface and reference the interface after the destructure. TypeScript is then able to understand that the function ...
Jan 17, 2023 · The same code using destructuring. That’s a lot more concise. And notice how we’re setting the value for id.When both variables have the same name, { id: id } can become just { id }.You will ...
Dec 9, 2022 · The Destructuring Assignment is one of these aha moments you have as a software engineer. After spending your life trying to read values from arrays or objects, you discover the syntax that changes your life. Forever. This article will teach you the basics of destructuring arrays and objects.
Oct 25, 2024 · TypeScript Destructuring Assignment with Type. Destructuring assignment is a powerful feature in TypeScript that allows you to extract values from objects or arrays and bind them to variables. When combined with type annotations, TypeScript destructuring becomes even more robust and expressive. Basics of Destructuring Assignment
Jul 9, 2021 · The first of these is destructuring assignments. Destructuring Arrays. For example: const [one, two, three] = ["one", "two", "three"] While this is a trivial example, the opritunity here is to assign multiple values from an array at once. This would be an alternative to this;
Dec 15, 2022 · Destructuring TypeScript supports the following forms of Destructuring (literally named after de-structuring i.e. breaking up the structure): 1. Object Destructuring 2. Array Destructuring It is easy to think of destructuring as an inverse of structuring. The method of structuring in JavaScript is the object literal: