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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T09:22:58+00:00 2026-05-23T09:22:58+00:00

I wonder how the event-loop works in javascript, I am using node.js but I

  • 0

I wonder how the event-loop works in javascript,
I am using node.js but I guess that the same question apply to browsers.

I have some async call (let’s say setTimeout or $.ajax or fs.readFile)
and after a while the event-loop executes the callback

now when the callback is getting executed, what happens behind the scene?
Does the it revive the stack that it used when it invoked the async stuff?

In practice what is the context/this that the callback is living in?
and how does it work?

edit: thanks, I see..
just one more issue, how does the event loop “remembers” the scope of a callback?

  • 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-23T09:22:59+00:00Added an answer on May 23, 2026 at 9:22 am

    JavaScript uses function scoping, the scoping rules are the same in all JS environments. As Nican mentioned understanding closure is important to knowing what is available in your current scope.

    Basically a function “remembers” the environment in which it was defined. So if you use an inline anonymous function for your callback it will have access to all the variables that are available to its parent function and anything that is passed into it as an argument.

    A few resources regarding closures and scope in JavaScript:

    • Functions and function scope @ MDC
    • Closing The Book On JavaScript Closures
    • Stuart Langridge: Secrets of JavaScript Closures, part 1 (video)
    • Stuart Langridge: Secrets of JavaScript Closures, part 2 (video)

    Stoyan Stefanov’s book Object-Oriented JavaScript does a great job of explaining scoping in JavaScript and how the lexical scoping of functions work (see chapter 4). I’d recommend the book to anyone who is serious about JS programming.

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

Sidebar

Related Questions

So far I have only known and seen <f:event type=preRenderView listener=#{situationHelper.load}/> and I wonder
This question in mainly pointed at C/C++, but I guess other languages are relevant
i wonder how it works.. i have this code. it should paint pictures (Bitmap
In one HTML page I have a JavaScript function checkUpdates() that hits the server.
I wonder how to obtain feedback from an event? Situation: Let's say that a
wonder whether someone can help me with the following one... I have a struct
i wonder how i can solve the following problem. i have a horizontal scrollbar
I just wonder... I mainly use .NET but now I started to investigate WINAPI
I wrote a piped shell command that has multiple pipes in it that works
i wonder if somebody knows how to trigger thickbox from onRelease() event in flash.

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.