나무 숲

TIL / Javascript 가변인자 본문

Career/웹

TIL / Javascript 가변인자

wood.forest 2020. 1. 6. 11:30

Arguments

가변인자
: 함수 Arguments의 타입, 개수가 상관없다!

 

1. Arguments 개수 구하기

function GetArgsLength() {
    console.log(arguments.length);
}

GetArgsLength();          //0   
GetArgsLength(1);         //1
GetArgsLength(1, "2");    //2

 

2. Arguments 타입 구하기

function GetArgsType() {
    for (index in arguments) {
        console.log(typeof arguments[index]);
    }
}

GetArgsType();           //
GetArgsType(1, "2");     // number, string
GetArgsType(undefined);  // undefined
GetArgsType([1, 2, 3]);  // object

 

3. 응용

 

https://www.freecodecamp.org/learn/javascript-algorithms-and-data-structures/intermediate-algorithm-scripting/arguments-optional/

 

www.freecodecamp.org

 

느낌에 저 문제가 엄청 괜찮은 것 같다 ㅋㅋ

 

 

 

 

올림 : https://github.com/wooooooood/Today-I-Learned/blob/master/Javascript/Arguments.md

 

wooooooood/Today-I-Learned

Today I Learned - about EVERYTHING. Contribute to wooooooood/Today-I-Learned development by creating an account on GitHub.

github.com

 

728x90
반응형
Comments