Can we use window timing methods without procedures?

window.setTimeout(()=>{
    alert("Hi");
}, 3000);

I gather that we must use at least an anonymous procedure here, if we want to use the window method (it could have been setInterval() instead, of course).

Can we use window methods without procedures?

You can also do this

function sayHello() {
   alert('Hi');
}

setTimeout(sayHello, 3000);

Does the same thing, but it references an existing function instead of creating a new one.

But you can’t use setTimeout/setInterval without some sort of function.

So I gather from your reply that we just can’t use window timing methods without procedures.

Correct. What is it you want to do?

Why are you concerned about using procedures?

I wanted to learn if it’s possible to execute code in a timing method without procedure.

Primarily for the sake of learning because I am just fine with using procedures :slight_smile:

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.