lydiahallie / javascript-questions

A long list of (advanced) JavaScript questions, and their explanations :sparkles:

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Question 42 answer is INCORRECT

AnkitSharmaOnGithub opened this issue · comments

When you run this code into the browser, it prints "hello", every 2000 ms.

You should try to reframe this question to this:-
How to clear the setInterval method, which gives some output after every 1000 ms?

The question is misguiding along with the code snippet. Codesnippet can be removed.

Answer 42 is correctly phrased to me. It asks what the function setInterval invocation returns, not what it prints in the console, which is completely different.

Assuming to not change the available answers, your reframing would completely mislead the question because, again, the question is asking what setInterval returns, not how an interval should be cleared (the answer would be clearInterval, which is not there).

Last but not least, the console.log is only contextual (and maybe a bit misleading on purpose) to not leave the function empty. But if we change the function provided to setInterval in the question to the following one, your question won't subsist anymore. Try to answer the question with this example:

setInterval(() => {}, 1000);

Agreed with @alexandercerutti . Closing this issue for that reason.