mirror of
https://github.com/microsoft/frontend-bootcamp.git
synced 2026-01-26 14:56:42 +08:00
adding exercies for steps 2-1 and 2-2
This commit is contained in:
24
step2-01/demo/src/spread/index.ts
Normal file
24
step2-01/demo/src/spread/index.ts
Normal file
@@ -0,0 +1,24 @@
|
||||
// Destructuring
|
||||
var [a, b, ...rest] = [1, 2, 3, 4];
|
||||
console.log(a, b, rest); // 1,2,[3,4]
|
||||
|
||||
// Array assignment
|
||||
var list = [1, 2];
|
||||
list = [...list, 3, 4];
|
||||
console.log(list); // [1,2,3,4]
|
||||
|
||||
// Object assignment
|
||||
const point2D = { x: 1, y: 2 };
|
||||
const point3D = { ...point2D, z: 3 };
|
||||
|
||||
// Concat two objects
|
||||
const obj1 = { x: 1 };
|
||||
const obj2 = { y: 2 };
|
||||
|
||||
const obj3 = { ...obj1, ...obj2 };
|
||||
|
||||
// Destructuring object
|
||||
const { x } = obj3;
|
||||
|
||||
// adding an export to turn this into a "module"
|
||||
export default {};
|
||||
Reference in New Issue
Block a user