Javascript
[Javascript] throw new TypeError
insub4067
2021. 9. 23. 12:08
function add (x,y) {
if( typeof x !== 'number || typeof y !== 'number){
throw new TypeError('숫자만 입력해주세요');
}
return x + y
}
//expected output
console.log(add('a','b')); //TypeError: 숫자만 입력해주세요
Parameter로 들어오는 arguments에 대한 type을 평가하고 Error를 던져줄때 사용하는 Code