๐Ÿ”ฐobject destructuring

JS โŸฉ operator โŸฉ assignment โŸฉ destructuring โŸฉ object

// โญ๏ธ ๅฏๅ…ˆๅฎฃๅ‘Š่ฎŠๆ•ธ๏ผŒๅ† destructuring๏ผŒไฝ†่ฆใ€Œๅฐๅฟƒใ€โ—
let t, w, h;

// ------------------ ๐Ÿงจโ€ƒthere's a catchโ— --------------------
// โ›” SyntaxError: Unexpected token '='
//  {t, w, h} = opts;
//  ^^^^^^^^^ <------------ JS sees this as a "code block"โ—
// ------------------------------------------------------------

// โœ… wrap it in "parentheses", now it's OK.
    ({title: t, width: w, height: h} = opts);
//  ^                              ^

Last updated

Was this helpful?