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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T04:53:59+00:00 2026-05-29T04:53:59+00:00

Please consider the two snippets of code (the first prints Local eval, the second

  • 0

Please consider the two snippets of code (the first prints “Local eval”, the second prints “Global eval”):

(function f() { 
    var x;
    try {
        eval("x");
        console.log('Local eval');
    }
    catch (e) {
        console.log('Global eval');
    }
}())

and

var globalEval = eval;
(function f() { 
    var x;
    try {
        globalEval("x");
        console.log('Local eval');
    }
    catch (e) {
        console.log('Global eval');
    }
}())

It turns out that even though globalEval === eval evaluates to true, globalEval and eval behave differently because they have different names. (An eval can only be local if it is precisely written eval.)

How can I distinguish to two evals? Is there are a way to extract variable labels to infer behaviour?

  • 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-29T04:54:00+00:00Added an answer on May 29, 2026 at 4:54 am

    Interesting. But since you’re in control of where/when your reference to eval is defined, you get to say how to distinguish them. For example have an object that has the “function pointer” AND something to indicate the scope – if you define it, you know where you stand.

    I.e. myEvaluator.scope would tell you info about where the eval scope was captuerd, and myEvaluator.eval could be used to evaluate.

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

Sidebar

Related Questions

Please consider the two following snippets of code: (function f() { var x; try
Please consider the two snippets of code (notice the distinction between string and integer):
Please consider the following two initialization methods. The first method simply passes the value
This is a complex question, please consider carefully before answering. Consider this situation. Two
Please consider the following fork() / SIGCHLD pseudo-code. // main program excerpt for (;;)
Please consider this code: template<typename T> char (&f(T[1]))[1]; template<typename T> char (&f(...))[2]; int main()
Please consider the following code: public class Person ( public string FirstName {get; set;}
Please consider the following: http://jsfiddle.net/CASM6/9/ I have two rows of tabs. there are two
please consider the code below, and tell me what I'm doing wrong. I want
Please consider the following piece of code: int main() { typedef boost::ptr_vector<int> ptr_vector; ptr_vector

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.