yuzunsang / JS-deep-dive-study

자바스크립트 딥 다이브 스터디✨
0 stars 3 forks source link

[CH18]함수와 일급 객체 #25

Open yuzunsang opened 3 months ago

yuzunsang commented 3 months ago

[퀴즈 예시] Q. 여기에 퀴즈 설명을 적으세요.

적을 코드가 있다면 밑에 적어주세요. (백틱 3개로 코드를 감싸면 코드 양식을 적을 수 있습니다.)

// 예시 코드
const arr = [1, 2, 3];
console.log("Hello");

아래 코드를 복붙해서 정답을 적어주세요.

<details>
    <summary>정답</summary>
    <div markdown="1">    
    정답 설명
    </div>
</details>
yuzunsang commented 3 months ago

Q. [객관식] sum 함수의 프로퍼티가 아닌 것은?

function sum(x, y) {
    return x + y;
}

1번 : __proto__ 2번 : caller 3번 : prototype 4번 : length 5번 : arguments

정답
1번
__proto__ 는 접근자 프로퍼티이며,
함수 객체 고유의 프로퍼티가 아닌 Object.prototype 객체의 프로퍼티를 상속받은 것이다.
bo-eun commented 3 months ago

Q. 다음 함수의 실행 결과를 예상해보고 설명하세요.

function foo(func) {
  return func();
}

function bar() {
  return bar.caller;
}

console.log(foo(bar)); // 1
console.log(bar()); // 2
정답
함수의 caller프로퍼티는 함수 자신을 호출한 함수를 가리키므로 아래와 같은 결과가 나온다.
1. function foo(func) {...}
2. null
sueonnn commented 3 months ago

function baz(x, y) { return x * y; } console.log(baz.length);