js 执行总结1

一、

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 }

原文地址:https://www.cnblogs.com/shangyueyue/p/11038722.html