Destructuring is a neat way of cleaning up JavaScript code. In this post we'll go through lots of different areas destructuring helps the readability of our code.
Destructuring is a neat way of cleaning up JavaScript code. In this post we’ll go through lots of different areas destructuring helps the readability of our code.
When a function parameter is an object rather than a primitive, destructuring can be used to break the object into the parts that the function references. The code below is without any destructuring:
async function logData(options) {
if (!options.skip) {
const response = await fetch(options.path);
const data = await response.json();
console.log(data);
}
}
This can be refactored into the following by destructuring the options
parameter:
async function logData({ skip, path }) {
if (!skip) {
const response = await fetch(path);
const data = await response.json();
console.log(data);
}
}
This is arguably cleaner because we are referencing the parameter properties, skip
and path
, directly rather than through the options
parameter name.
A really neat thing about this approach is that we can apply default values to the destructured properties.
💲 Live CollabPlay: https://youtu.be/B6LCFSPdsE0 💲 Hospedagem com Desconto Exclusivo: https://tekers.tech/4e587 Não é todo programador que gosta de compartilh...
#vscode Hello, my friends and fellow developers, this video is all about User Snippets. That means the Snippets (Code Shortcuts) that you can make for yourse...
We are pleased to announce that the July release of the Python extension is now available for Visual Studio Code. You can download the Python extension from the Marketplace, or install it directly from the extension gallery in Visual Studio Code. If you already have the Python extension installed, you can also get the latest update by restarting Visual Studio Code. You can read more about Python support in Visual Studio Code in the documentation .
If you’re looking for a fast and lightweight open-source code editor, Visual Studio Code has you covered. Come for a deep dive into the features of Visual Studio Code which provide a rich, productive environment for C++ development.
We speak to the creator of Visual Studio Code about the early challenges to now becoming the most popular development environment in the world.