prgrms-web-devcourse / FEDC5_Modern_JavaScript_DeepDive

데브코스 프론트엔드 5기 조윤호팀 - 모던 자바스크립트 Deep Dive 스터디
2 stars 4 forks source link

[제너레이터] 제너레이터 예제2 #65

Open junly21 opened 11 months ago

junly21 commented 11 months ago
function* genFunc(){
    const x = yield 1;
    const y = yield (x+10)
    yield x+y 
    }

 const gen2 = genFunc()

위 코드에 대하여 다음과 같이 실행할 경우

 gen2.next(10)
 gen2.next(10)
 gen2.next()
 gen2.next()

각각의 실행 코드에 대해서 반환되는 객체를 작성해주세요

Heeeera commented 11 months ago
답변 ```javascript { value: 1, done: false } { value: 20, done: false } { value: 20, done: false } { value: undefined, done: true } ```
choi-ik commented 11 months ago
정답 {value: 1, done: false} {value: 20, done: false} {value: 30, done: false} {value: undefined, done:true}
hj9118 commented 11 months ago
정답 ```js {value: 1, done: false} {value: 20, done: false} {value: NaN , done: true} {value: undefined, done: true} ```