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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T11:09:42+00:00 2026-05-26T11:09:42+00:00

I stumbled upon the function .globalEval() from browsing the jQuery source. There is very

  • 0

I stumbled upon the function .globalEval() from browsing the jQuery source. There is very brief documentation which I don’t understand. Apparently, it is “important for loading external scripts dynamically”. Why? The source is also somewhat obscure:

globalEval: function( data ) {
    if ( data && rnotwhite.test( data ) ) {
        // We use execScript on Internet Explorer
        // We use an anonymous function so that context is window
        // rather than jQuery in Firefox
        ( window.execScript || function( data ) {
            window[ "eval" ].call( window, data );
        } )( data );
    }
},

Do people actually use this in real life? If so, for what?

  • 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-26T11:09:43+00:00Added an answer on May 26, 2026 at 11:09 am

    It is used, as the name suggests, to execute the eval code in the global context. For example, consider the following (jsFiddle):

    function example(){
      $.globalEval("var example1 = 'first';");
      eval("var example2 = 'second';");
        console.log("In function: " + example1); //Prints 'first'
        console.log("In function: " + example2); //Prints 'second'
    }
    example();
    console.log("Global: " + example1); //Prints 'first'
    console.log("Global: " + example2); //ReferenceError
    

    Because example1 was defined using globalEval, it’s in the global scope. Using plain old normal eval, the variable is only availble in the scope in which eval is called.

    It can be useful if you want to load another JS script, and you want to execute that script in the global context (for example, above, we might need example1 to be available outside of the example function, so we have to use globalEval.

    I’m not sure why the jQuery source uses window[ "eval" ].call instead of just eval.call, but I’m sure someone could explain 🙂

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

Sidebar

Related Questions

I stumbled upon the .sub function from browsing the jQuery source. There is a
There is an eval() function in Python I stumbled upon while playing around. I
I stumbled upon this question from two years ago. Is there a way to
I am practicing using pointers and stumbled upon something I don't understand. The program
While delving into some old code I've stumbled upon a function which is used
I stumbled upon this question: 7 power 7 is 823543. Which higher power of
I just stumbled upon MainSoft's Grasshopper , which claims to cross-compile .Net ILM to
I have recently stumbled upon a problem with selecting relationship details from a 1
I stumbled upon an issue with event namespacing while developing a jQuery plugin. here
I am using MFC for gui development and I stumbled upon a function that

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.