JavaScript setTimeout() in Chrome console - Stack Overflow

admin2025-04-09  1

Why setTimeout doesn't work from Chrome console on some pages or what am I doing wrong?

setTimeout(function(){console.log('a');},3000);

output:

<- 6425

Example page:


EDIT: Seems that on some pages console.log() is being overridden ... as it's site specific problem, this question should be deleted. But can't do that, as it has answers.

Why setTimeout doesn't work from Chrome console on some pages or what am I doing wrong?

setTimeout(function(){console.log('a');},3000);

output:

<- 6425

Example page: http://olx.pl


EDIT: Seems that on some pages console.log() is being overridden ... as it's site specific problem, this question should be deleted. But can't do that, as it has answers.

Share Improve this question edited Oct 16, 2017 at 19:57 Flash Thunder asked Oct 16, 2017 at 19:20 Flash ThunderFlash Thunder 12.1k10 gold badges53 silver badges103 bronze badges 17
  • 1 window.setTimeout() on MDN. – Etheryte Commented Oct 16, 2017 at 19:21
  • 1 why you down vote my question when there is no answer for that in documentation? – Flash Thunder Commented Oct 16, 2017 at 19:25
  • 5 The number 6425 is the timeout id. So clearly it is at least creating the timeout. In 3 seconds, it should call the function. So why would it not show the log? Well is your console filtered to not show log lines? – epascarello Commented Oct 16, 2017 at 19:26
  • 2 LOL.... it works.... – epascarello Commented Oct 16, 2017 at 19:27
  • 2 No it outputs "a" after 3 seconds. – epascarello Commented Oct 16, 2017 at 19:28
 |  Show 12 more ments

1 Answer 1

Reset to default 3

It does work. The catch is you may not be waiting enough.

console.log(setTimeout(() => console.log('a'), 1000));

That number you get is the timeoutId. Anytime you call setTimeout or setInterval it returns a numeric ID which you can then pass to clearTimeout() or clearInterval() to abort it before it runs.

转载请注明原文地址:http://conceptsofalgorithm.com/Algorithm/1744203034a235890.html

最新回复(0)