6장 매개변수와 return문을 정리하라

설아아빠·2021년 12월 25일
0
post-thumbnail

1. 매개변수 기본값을 생성하라

        function convertWeight(weight, o = 0, r = 2) {
            const total = weight + (o / 16);
            const conversion = total / 2.2;

            return conversion + r;
        }

        console.log(convertWeight(10, 5));

2. 해체 할당으로 객체 속성에 접근하라

        const data = {
            a: 1,
            b: 2
        };
        const {a, b, c = 'defaults'} = data;
        console.log(a, b, c, data);

        const {...data1} = data;

        console.log(data1);

3. 키-값 할당을 단순화 하라

        //이건 좀 디버깅 하기 어려울것 같음
        const landscape = {
            title: 'landscape',
            location: [323, 424]
        }

        function test({location, ...details}) {
            console.log(location, details);
        }

        test(landscape);
profile
back-end(java), front-end (조금)

0개의 댓글