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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T05:33:25+00:00 2026-05-13T05:33:25+00:00

Very simple question: suppose I have the following js/jquery code doSomething(); $.get(url, callback); doSomethingElse();

  • 0

Very simple question: suppose I have the following js/jquery code

doSomething();

$.get(url, callback);

doSomethingElse();

I understand that right after the GET request is sent doSomethingElse() starts being executed. Now suppose that the server’s reply arrives while doSomethingElse() is executing. What happens?

  • Does the callback run in a separate thread in parallel to doSomethingElse()?
  • Does the execution of doSomethingElse() pause until the callback runs and returns?
  • Does the callback only get called once doSomethingElse() has returned?

Thank you for any insight!

lara

  • 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-13T05:33:25+00:00Added an answer on May 13, 2026 at 5:33 am

    No, JavaScript in web browsers is single-threaded, by design. That means that although the ajax call may start immediately (and be processed by another thread in the browser), your callback won’t happen until the JavaScript interpreter is next idle. Things to do get queued up waiting for the interpreter to become idle and process them.

    Edit Answering your specific questions:

    Does the callback run in a separate thread in parallel to doSomethingElse()?

    No, the callback will run in the same logical thread as doSomethingElse. (It would be implementation-dependant whether that’s the same actual underlying OS thread, but you have no way of knowing and you don’t care; logically, it’s the same thread.)

    Does the execution of doSomethingElse() pause until the callback runs and returns?

    By default, the get will be asynchronous, so no. doSomethingElse initiates the request, but then continues. (It’s possible to do a synchronous get via the underlying XmlHttpRequest mechanism, but it’s a very bad idea — tends to lock up the UI of the browser completely while the request is running, which is ugly — and I don’t know how you do it with jQuery.)

    Does the callback only get called once doSomethingElse() has returned?

    With an asynchronous get (the usual kind), you can be certain that doSomethingElse will finish before the callback gets called, yes. This is because the JavaScript interpreter will only do one thing at a time, and it doesn’t switch to doing a new thing until it’s done with the current one. So although doSomethingElse triggers the get (and the get may be processed by other, non-JavaScript threads in parallel to JavaScript), your callback won’t happen until after the interpreter is done with doSomethingElse and anything that called it.

    I wouldn’t be surprised if at some point we start getting multiple threads in browser-based JavaScript, but if and when we do, it’ll have to be explicit, since we all happily assume one thread for the moment.

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

Sidebar

Related Questions

Here's a very simple question. I have an SP that inserts a row into
I am learning LINQ and have a very simple question that I think will
I have a very simple question. I want to test whether a particular port
Hopefully very simple SQL question - I'm just blacking out :) I have a
Very simple question, is there any cloud server enviroments avaliable these days for us
This is a very simple question with a simple answer, but it is not
This must be a very simple question, but I don't seem to be able
I know this is a darn simple question, but I'm very used to using
Warning - I am very new to NHibernate. I know this question seems simple
This very simple code gives me tons of errors: #include <iostream> #include <string> int

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.