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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T17:14:46+00:00 2026-06-09T17:14:46+00:00

Why is this piece of code : var myBreak = ‘break;’; for(var i=0; i

  • 0

Why is this piece of code :

    var myBreak = 'break;';
    for(var i=0; i < 5; i++) {
        console.log('i is : ' + i);
        eval(myBreak);
    }
    console.log('done !');

triggering the :

unlabelled break must be inside loop or switch

error message in Firebug in place of returning done ! in the console ?

Is it not possible to eval() break statements ?

Thank you in advance !

EDIT :

I’m getting confused now. ^^

  • Why does it fail ?
  • Is Jack Wanders right then with eval having it’s
    own ‘execution context’ ?
  • If yes, why isn’t his example working ?
  • 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-06-09T17:14:47+00:00Added an answer on June 9, 2026 at 5:14 pm

    eval parses/evaluates code in a new instance of the JavaScript interpreter. The code eventually executes in context with the original interpreter’s code but the code has to be able to execute without that external context because the new instance is blind to it.

    So alert(eval(this.constructor.name)) will give you the proper object context name (window in global).

    But these will fail because the instances don’t ‘see’ each other’s code until it’s been evaluated by the separate interpreters and at this phase one piece fails without the other:

    • try{}eval('catch(){}');

    • for(;;){ eval('break;'); }

    • myLoop: eval('for(;;){ break myLoop; }');

    Short version: Code will work as expected but anything in an eval would have to be something you could fire in any other context by itself.

    So basically, preliminary parsing/error-checking is done before values and scope and object context are considered. Once that’s all done the code can act in concert and be checked for things like whether you’re calling a var that hasn’t been defined yet. Before that, the new interpreter only sees what’s in the eval when it checks for errors. In the case of a that break, what it doesn’t see is a loop or a switch surrounding it.

    Loop labels are considered during this early parsing/evaluation phase whereas stuff like var existence and function labels appear to be checked later.

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

Sidebar

Related Questions

I'm using this piece of code from a fellow SO user: $(#rightSubMenu).mousemove(function(e){ console.log('executed'); var
Consider this piece of code var crazy = function() { console.log(this); console.log(this.isCrazy); // wrong.
So I have this piece of code : var imageList = (from stepImages in
I've been here and accordingly found out that this piece of code here var
I have this piece of code in javascript: var catId = $.getURLParam(category); In my
I have this piece of code: function func1(text) { var pattern = /([\s\S]*?)(\<\?(?:attrib |if
Hi all Why this piece of javascript code doesn't work on firefox var nfiles
Check out this piece of JavaScript code: (function (w, d) { var loader =
I have problem with this piece of code: var el = $('div#editor'); el.find('*[contentEditable]').removeAttr('contentEditable'); It
This piece of code causes Chrome to crash: function forecastTemp(forecast) { var end =

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.