how to destructuring object javascript with different name code example
Example 1: javascript object destructuring rename
// Renaming
// ----------------------------------------------
const { bar: foo } = { bar: 123 };
bar // Uncaught ReferenceError: bar is not defined
foo // 123
// Renaming with default value
// ----------------------------------------------
const { bar: foo = 123 } = { potato: 456 };
bar // Uncaught ReferenceError: bar is not defined
foo // 123
potato // Uncaught ReferenceError: potato is not defined
Example 2: typescript object destructuring
// declare an interface or a type
interface Person {
name: string;
age: string;
}
// destructure name and age from `obj` variable.
const { name, age }: Person = obj;