1、输出结果
let a = { apple: "苹果", water: "水", money: [100, 999] },
b = a,
c = Object.assign({}, a),
d = { ...a },
e = JSON.parse(JSON.stringify(a)),
f = Object.assign(a);
a.water = "修改后的水";
a.money[0] = "修改后的金额";
console.log(b);
console.log(c);
console.log(d);
console.log(e);
console.log(f);
2、输出结果
function Fn() {
var num = 0;
this.x = 20;
this.getX = function () {
console.log(x);
};
}
var f1 = new Fn();
console.log(f1.x);
console.log(num);
console.log(f1.getX);
3、输出结果
var a = {};
b = { b: "b" };
c = { c: "c" };
d = { d: "d" };
a[b] = 123;
a[c] = 456;
a[d] = 789;
console.log(a);
console.log(b);
console.log(c);
console.log(a[b]);
console.log(a[c]);
console.log(a[c]);
4、输入条件使成立
let a = {
num: 1,
toString: function () {
console.log("A ---- toString");
},
valueOf: function () {
return this.num++;
},
};
var b = {
num: 1,
toString: function () {
return this.num++;
},
valueOf: function () {
console.log("B ---- valueOf");
},
};
if (a == 1 && a == 2 && a == 3) {
console.log("aaaaaaa");
} else {
console.log("a不被执行");
}
if (b == 1 && b == 2 && b == 3) {
console.log("bbbbbbb");
} else {
console.log("b不被执行");
}
5、输出结果
const data = [
{
label: "武汉市",
children: [
{
label: "洪山区",
children: [{ label: "永丰街道" }, { label: "五里墩街道" }],
},
{
label: "武昌区",
children: [{ label: "安山街道" }, { label: "建安街道" }],
},
],
},
];
const value = "建安";
data.reduce((preVal, curVal) => {}, []);