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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T00:34:00+00:00 2026-05-23T00:34:00+00:00

I am confused regarding the order of evaluation in javascript. For ex, this is

  • 0

I am confused regarding the order of evaluation in javascript. For ex, this is the code I have written

this.getTabUrl=function()
{
    this.logToConsole("1"+"getTabUrl is called");

    var myUrl
    chrome.tabs.getSelected(null, function(tab)
    {
        myUrl = tab.url;
        console.log("2"+tab.url);
        console.log("3"+myUrl);
        //this.parent.logToConsole(tabUrl);

    });

    this.tabUrl=myUrl;

    this.logToConsole("3.1"+myUrl);
    this.logToConsole("4"+this.tabUrl);

    return myUrl;

}   

When I call this function, this is the Output I get

> 1getTabUrl is called
> 3.1undefined 
> 4undefined 
> 2undefined

How come 3.1 and 4 is evaluated first before 2.

  • 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-23T00:34:01+00:00Added an answer on May 23, 2026 at 12:34 am

    The function passed to chrome.tabs.getSelected() is executed asynchronously.

    You need to put everything that needs whatever gets passed to the callback inside the callback function. Note that this means you cannot return a value from the outer function that relies on something from the callback. You need to accept a callback argument instead and call it with the return value.

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

Sidebar

Related Questions

I have been so confused lately regarding difference between predicate and function in first
I have the following javascript : var MyObject = (function() { function Setup(args) {
I am learning about SOAP implementation and have become somewhat confused regarding the appropriate
Im confused regarding which scope should i use. Here i have a module, that
I have read many articles regarding layout, but I am still quitely confused. My
I tried this dummy code below to test unnamed namespace. I have the following
i have a function called fun1() , which is used for recursion. I am
I'm a bit confused regarding the document architecture. Lets look at MSN for Mac
I'm confused regarding each() and .each()... I think I need to use both, but
I need help regarding DDA algorithm , i'm confused by the tutorial which i

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.