Spread syntax
- if you want to add array inside middle of array
12const spread = [1, 2, 3];const arr = [0, ...spread, 4]; // [0, 1, 2, 3, 4])
cs - if it is empty array, it will return nothing
12const spread = [];const arr = [0, ...spread, 4]; // [0, 4]
cs - can merge arrays same as concat method
1234const arr1 =[1, 2, 3];const arr2 = [3, 4, 5];const concatenated = [...arr1, ...arr2]; // [0, 1, 2, 3, 4, 5]arr1.concat(arr2); // [0, 1, 2, 3, 4, 5]
cs - can merge objects as well
1234567891011121314151617const paige = {firstName: 'Paige',LastName: 'Kim',};const me = {hobby: 'piltaes',todos: ['coplit', 'koans'],};const merged = {...paige, ...me};/* const merged = {firstName: 'Paige',LastName: 'Kim',hobby: 'piltaes',todos: ['coplit', 'koans'],};*/
cs - if spread syntax goes inside parameter, it become 'rest parameter(rest syntax)'
- useful when numbers of parameters were not set
- returns arguments with 'ARRAY'
1234function pintMaxNums(...args) {console.log(args); //[10, 30, 40]}pintMaxNums(10, 30, 40);
cs
Object
- ===
- To compare 'REFERENCE' only in object!!
123456789101112const person = {son: {age: 9,},};const boy = person.son;boy.age = 20;expect(person.son.age).toBe(20);expect(person.son === boy).toBe(true);expect(person.son === { age: 9 }).toBe(false);expect(person.son === { age: 20 }).toBe(false);cs
- To compare 'REFERENCE' only in object!!
'TIL' 카테고리의 다른 글
TIL 2020.11.11 (0) | 2020.11.14 |
---|---|
TIL 2020.11.09 (0) | 2020.11.09 |
TIL 2020.11.07 (0) | 2020.11.07 |
TIL 2020.11.06 (0) | 2020.11.06 |
TIL 2020.11.05 (0) | 2020.11.05 |