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

  • Home
  • SEARCH
  • 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 6914267
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T09:19:31+00:00 2026-05-27T09:19:31+00:00

I run these code on my firefox, and the console gets 3 2 1

  • 0

I run these code on my firefox, and the console gets 3 2 1, which means statements run before the former ones end.

function test(){
    setTimeout(function(){console.log(1)},1000);    //statement 0
    setTimeout(function(){console.log(2)},500);     //statement 1
}
test();
console.log(3);                                     //statement 2

Is it a feature of javascript, and do I have to double-check a variable after assigning it some value? Cuz’ it’s way too complicated.

var a;
while(a!==get('some')){
    a=get('some');
    if(a===get('some')){
       whatShouldBeRun();afterGetSome();
       break;
    }
}
  • 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-27T09:19:32+00:00Added an answer on May 27, 2026 at 9:19 am

    That is exactly what you have asked it to do. Firstly, you ask it to kick off two statements to run some point in the future. Then you write “3”. The first of those statements whose time it is to run then runs, and writes “2”. Finally, the third of these runs and writes “1”.

    If you are using asynchronous processing – settimeout – then yes you need to handle this as with any other language. But then if you need it to run in order, don’t tell it to run asynchronously.

    To get them to run one after the other:

    function test()
    {
        setTimeout(function()
        {
            console.log(1);setTimeout(function()
               {
                      console.log(2);console.log(3)
               },500)
        },1000);
    }
    
    test();
    

    [I might have some of this wrong]

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

Sidebar

Related Questions

There are a number of run-time differences in compatible code between these two versions
I'm developing a Firefox extension and have the following code: function initialize() { //
I've got this code... function disableSheets(){ console.log(document.styleSheets.length); var c = document.styleSheets.length; for(var i=0;i<c;i++){ console.log(document.styleSheets[i]);
When I run the code below, Safari's debug console tells me: TypeError: Result of
I have some jQuery/JavaScript code that I want to run only when there is
Is there a way to run plain c code on top of the JVM?
Is there a way to run some sort of code analysis to find code
Is there any way I could run the following 'logical code' to actually work?
I remember there existed a testing program/library that will run your code and/or unit
I have recently run across these terms few times but I am quite confused

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.