Hello.
Trying to loop the javascript execution. But I get the error -
Uncaught ReferenceError: test is not defined at: 1: 1.
What did you do wrong?
function test() { console.log('test_'); setTimeout('test()', 1000); } test(); Hello.
Trying to loop the javascript execution. But I get the error -
Uncaught ReferenceError: test is not defined at: 1: 1.
What did you do wrong?
function test() { console.log('test_'); setTimeout('test()', 1000); } test(); setTimeout takes a function and a time as arguments. You passed a string. It should be like this
function test() { console.log('test_'); setTimeout(test, 1000); } test(); Your code is inside another function. Because of this, the test function is not visible in the global scope.
function starter() { function test() { console.log('test_'); setTimeout('test()', 1000); } test(); } starter(); Without a wrapper, it works:
function test() { console.log('test_'); setTimeout('test()', 1000); } test(); Therefore, it is better to submit to setTimeout not a line of code, but a link to a function. This works regardless of the presence / absence of a wrapper:
function starter() { function test() { console.log('test_'); setTimeout(test, 1000); } test(); } starter(); Source: https://ru.stackoverflow.com/questions/829966/
All Articles