Try this:
function fun(a, b) {
return a + b
}
setTimeout(() => console.log(fun(1, 1)), 5000);
If you have a multiline function to execute:
setTimeout(() => {
fun(1, 1);
fun(3, 4)
}, 5000);
Since your requirement is a delay of five seconds and not five thousand miliseconds, you can improve the readability by specifying the number of seconds and then multiplying it by 1000:
setTimeout(() => {
fun(1, 1);
}, 5 * 1000);
Don't forget that setTimeout
is asynchronous, so any lines of code following fun(1, 1)
will eventually be executed prior to fun