setInterval schedules timedFunction to run every 1000 ms.
It returns an interval ID (here stored in timerId), which is used to cancel the interval later.
To cancel:
Use clearInterval(timerId);
This is the standard browser (and Node.js) API:
let id = setInterval(fn, delay);
clearInterval(id); stops future executions of that interval.
Check other options:
B. removeInterval(timerId);
There is no removeInterval function in the standard JavaScript timer API.
C. removeInterval(timedFunction);
Again, no such function; and timers are cancelled by ID, not by the callback function reference.
D. clearInterval(timedFunction);
clearInterval expects the ID returned by setInterval, not the callback function.
Passing the function does not cancel the timer.
Therefore, the correct statement is:
Answer: A
Study Guide / Concept References (no links):
Timer APIs: setInterval and clearInterval
Relationship between timer ID and cancellation
Difference between interval ID and callback function
Basic async timing patterns in JavaScript
Contribute your Thoughts:
Chosen Answer:
This is a voting comment (?). You can switch to a simple comment. It is better to Upvote an existing comment if you don't have anything to add.
Submit