Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8310233
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T19:23:13+00:00 2026-06-08T19:23:13+00:00

How can an inner function call a parent function after it has expired? setTimeout(main,

  • 0

How can an inner function call a parent function after it has expired?

setTimeout(main, 2000);
function main(){
    /* .... code */
    setTimeout(console.log("hello after 5 seconds"), 5000);
}

The intended action is to print hello after 5 seconds in 5 seconds (7 total); with the above code it prints it in 2 seconds.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T19:23:15+00:00Added an answer on June 8, 2026 at 7:23 pm

    You need to pass setTimeout function references. With setTimeout(console.log("hello after 5 seconds"), 5000);, you call console.log immediately. Any time you write () after a function name, you’re invoking it.

    console.log returns undefined, which is what is passed to setTimeout. It just ignores the undefined value and does nothing. (And it doesn’t throw any errors.)

    If you need to pass parameters to your callback function, there are a few different ways to go.

    Anonymous function:

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

    Return a function:

    function logger(msg) {
        return function() {
            console.log(msg);
        }
    }
    
    // now, whenever you need to do a setTimeout...
    setTimeout(logger('...'), 5000);
    

    This works because invoking logger simply returns a new anonymous function that closes over msg. The returned function is what is actually passed to setTimeout, and when the callback is fired, it has access to msg via the closure.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an object and it has another inner object. How can I call
I can extend an inner class/trait inside the outer class or inside a class
how can I avoid this in jQuery: $(this).parents(.node-inner).children().children().children(); I tried: $(this).parents(.node-inner).children(.className); but it doesn't
A class can be a subclass of itself if its inner class extend the
Are anonymous inner classes private by default? Can I make them public? I need
In MySQL you can use the syntax DELETE t1,t2 FROM table1 AS t1 INNER
With Selenium IDE, how can I test if an element's inner text contains a
I have the following function call: public static MvcHtmlString NavLinks( this HtmlHelper helper, IList<MenuItem>
I have this code: (function ($) { $(document).ready(function() { test(hola,caracola); }); function test(somevar1, somevar2)
Suppose I have the following python code: def outer(): string = def inner(): string

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.