loading...

Destructuring - renaming and default value

318097 profile image Mehul Lakhanpal Originally published at codedrops.tech ・1 min read
const response = {
  msg: "success",
  tags: ["programming", "javascript", "computer"],
  body: {
    count: 5,
    data: ["File 1", "File 2"],
  },
};

// The key exists
const { msg: message = 'Hello' } = response;
console.log(message); // success

// The key does not exist
const { search: searchText = "programming" } = response;
console.log(searchText); // programming

Thanks for reading 💙

Follow @codedrops.tech for daily posts.

InstagramTwitterFacebook

Micro-Learning ● Web Development ● Javascript ● MERN stack ● Javascript

codedrops.tech

Discussion

pic
Editor guide