一、

function sayHi() {
  let x;
  let y;
  try {
    throw new Error();
  } catch (x) { // 局部
    x = 1;
    console.log(x); // 1
    y = 2;
  }
  console.log(x); // undefined
  console.log(y); // 2
}
sayHi()

二、对象的键只能是string 如果是对象,会调用toString 方法,转换成[object Object]

// object
const aObj = { a: 1 };
const bObj = { b: 1 };
const c = {};
c[aObj] = 123;
c[bObj] = 235;
console.log(c[aObj]); // 235

 三、

const obj1 = { a: 'shang', b: 'yy', a: 'huyating' };
console.log(obj1); // { a: 'huyating', b: 'yy' }
const obj2 = { name: 'shangyy', age: 18 };
const obj3 = { name: 'huyating' };
console.log({ ...obj2, ...obj3 }); // { name: 'huyating', age: 18 }

 

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-11-19
  • 2021-12-23
  • 2021-10-27
  • 2021-08-25
  • 2021-10-04
猜你喜欢
  • 2021-08-17
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-01-07
  • 2021-09-29
  • 2022-12-23
相关资源
相似解决方案