setTimeout in javascript within function

function, javascript, settimeout

Solution

When referencing a function, you need to leave off the brackets.

setTimeout(func1,10000);

Problem

I have two functions like below, ``` func1 = function(){ console.log("func1 is called"); } func2 = function(){ console.log("func2 is called"); setTimeout(func1(),10000) } ``` When I make a call like `func2()`. I get the output but not the expected one.As you can see I have used a `setTimeout()` in `func2` and I expect some delay as specified before `func1` gets executed. But no delay is observed both the lines gets printed to console at the same time. What am I doing wrong here or am I missing anything? Please help..

Original source

Related problems