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 565427
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T12:52:15+00:00 2026-05-13T12:52:15+00:00

What are closures and callbacks in JavaScript? I’ve yet to find a good explanation

  • 0

What are closures and callbacks in JavaScript? I’ve yet to find a good explanation of either.

  • 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-05-13T12:52:16+00:00Added an answer on May 13, 2026 at 12:52 pm

    Closures have already been well handled in Stackoverflow here is just a selection:-

    How does a javascript closure work?
    What exactly does “closure” refer to in JavaScript?
    can you say this is a right example of Javascript Closure.. Where the places we need to consider avoiding the closures??
    JavaScript scope and closure
    Javascript Closures and ‘this’ context
    JavaScript – How do I learn about “closures” usage?

    Callbacks are a simpler concept. A callback is basically where a function accepts another function as a parameter. At some point during execution the called function will execute the function passed as a parameter, this is a callback. Quite often the callback actually happens as an asynchronous event, in which case the called function may return without having executed the callback, that may happen later. Here is a common (browser based) example:-

     function fn() { alert("Hello, World"); }
     window.setTimeout(fn, 5000);
    

    Here the function fn is passed as a callback to the setTimeout function. Set timeout returns immediately however 5 seconds later the function passed as a callback is executed.

    Closures and callbacks

    Quite often the reason that closures get created (either incidentally, accidentally or deliberately) is the need to create a callback. For example:-

     function AlertThisLater(message, timeout)
     {
         function fn() { alert(message); }
         window.setTimeout(fn, timeout);
     }
    
     AlertThisLater("Hello, World!", 5000);
    

    (Please read some of the linked posts to grasp closures)

    A closure is created containing in part the message parameter, fn is executed quite some time after the call to AlertThisLater has returned, yet fn still has access to the original content of message.

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

Sidebar

Related Questions

What value do we get by using closures in JavaScript for implementing callbacks and
I am reading about closures in Javascript: The Good Parts book. There is following
I'm rusty with delegates and closures in JavaScript, and think I came across a
I was listening to Crockford's talk on JavaScript closures and am convinced of the
I am trying to understand how far I can go with PHP5's closures/callbacks, but
I've been trying to understand Javascript closures, and thought I was onto something. I
Functions with closures seem to break when used with eval . (eval {:fn (let
Possible Duplicate: What are ‘closures’ in .NET? I am currently looking at lambda expression
I'm slowly understanding closures more and more, and the following code works. I'm wondering
I've read through previous topics on closures on stackflow and other sources and one

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.