강의

멘토링

커뮤니티

Inflearn Community Q&A

bjw16221702's profile image
bjw16221702

asked

[Renewal] Introduction to JavaScript in Zero Seconds through Coding Self-Study

Timer stopped and started again

clearInterval(intervalId) 질문이요!!

Written on

·

292

0

const clickButton = () => {
  // 클릭 하자마자 실행
  clearInterval(intervalId);
  console.log(intervalId);
  setTimeout(() => {
    // 클릭 후 1초 후에 실행
    clearInterval(intervalId);
    console.log(intervalId);
    intervalId = setInterval(changeComputerHand, 50);
  }, 1000);
};
 
이 부분에서 연속으로 버튼 클릭이 아니라 1초 이상의 간격으로 버튼을 눌렀을 떄는 두번쨰 clearInterval이 작동이
안된다고 생각하면 될까요?? 이미 인터벌을 clear했는데 아무것도 없는 interval을 클리어가 가능한가요??
자바스크립트javascript

Answer 1

0

zerocho님의 프로필 이미지
zerocho
Instructor

clearInterval은 실행되나 이미 클리어됐으므로 아무 일이 일어나지 않습니다~

Donte님의 프로필 이미지
Donte
Questioner

답변 감사합니다!
그럼 클리어된걸 다시 또 클리어하는건데 에러 발생은 없다는 말씀이신거죠??

zerocho님의 프로필 이미지
zerocho
Instructor

네 맞습니다~

bjw16221702's profile image
bjw16221702

asked

Ask a question