# ES6 考核
1. 请实现以下功能:
```js
let name = '张三',
gender = '男';
console.log(person); // {name: '张三', gender: '男'}
```
2. 请实现以下功能:
```js
let person = {
name: '张三',
gender: '男',
age: 14,
job: '学生'
}
console.log(name, gender, props); // 张三 男 {age: 14, job: "学生"}
```
3. 请实现以下功能:
```js
{
let age = 15;
console.log(age); // age = ?
}
console.log(age); // age = ?
```
4. 交换 a, b 值
```js
let a = 1, b = 2;
console.log(a, b); // 2 1
```
5. 请实现以下功能
```js
let str = '7';
console.log(str); // 017
```
6. 看题目
```js
function log(x, y = 'World'){
console.log(x, y);
}
log('Hello'); // ?
log('Hello', 'JJ'); // ?
```
7. 实现以下功能
```js
let person = {
name: '张三',
gender: '男',
}
console.log(person); // {name: "张三", gender: "男", age: 14, job: "学生"}
```
## 附加题
输出 i 的值
```js
for (var i = 0; i < 5; i++) {
console.log(i);
}
for (var i = 0; i < 5; i++) {
setTimeout(function () {
console.log(i);
}, 1000 * i);
}
for (var i = 0; i < 5; i++) {
(function (i) {
setTimeout(function () {
console.log(i);
}, i * 1000);
})(i);
}
for (var i = 0; i < 5; i++) {
(function () {
setTimeout(function () {
console.log(i);
}, i * 1000);
})(i);
}
for (var i = 0; i < 5; i++) {
setTimeout((function (i) {
console.log(i);
})(i), i * 1000);
}
setTimeout(function () {
console.log(1)
}, 0);
new Promise(function executor(resolve) {
console.log(2);
for (var i = 0; i < 10000; i++) {
i == 9999 && resolve();
}
console.log(3);
}).then(function () {
console.log(4);
});
console.log(5);
```
网友评论