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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T05:35:41+00:00 2026-06-04T05:35:41+00:00

If I create a trivial labeled statement such as: foo: do { alert(‘hi’) }

  • 0

If I create a trivial labeled statement such as:

foo: do { alert('hi') } while (false)

Is there any way to clone foo?

  • 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-04T05:35:42+00:00Added an answer on June 4, 2026 at 5:35 am

    No, apparently this is not possible. Labels cannot be used in an assignment statement and the scope of a label is the conditional block of the loop in which it is defined.

    pastureLoop:
    for (i = 0; i < pastureLen; i++)
    {
       var pasture = pastures[i];
       var cows = pasture.getCows();
    
       var j, numCows = cows.length;
       for (j = 0; j < numCows; j++)
       {
          var cow = cows[j];
          if (cow.isSick())
             { break pastureLoop; }
    
          healthyCows++;
       }
    }
    
    
    pastureLoop:
    for (i = 0; i < pastureLen; i++)
    {
       var pasture = pastures[i];
       var cows = pasture.getCows();
    
       var j, numCows = cows.length;
       for (j = 0; j < numCows; j++)
       {
          var cow = cows[j];
          if (cow.isEating())
             { continue pastureLoop; }
       }
    
       // No cows were eating, so fire the callback for pasture[i]
       pasture.executeCallback();    // or whatever
    }
    

    The closest alternative is a labelled function declaration in non-strict mode:

    B.3.2 Labelled Function Declarations

    Prior to ECMAScript 2015, the specification of LabelledStatement did not allow for the association of a statement label with a FunctionDeclaration. However, a labelled FunctionDeclaration was an allowable extension for non-strict code and most browser-hosted ECMAScript implementations supported that extension. In ECMAScript 2015, the grammar productions for LabelledStatement permits use of FunctionDeclaration as a LabelledItem but 13.13.1 includes an Early Error rule that produces a Syntax Error if that occurs. For web browser compatibility, that rule is modified with the addition of the underlined text:

    LabelledItem : FunctionDeclaration

    It is a Syntax Error if any strict mode source code matches this rule.
    

    This can be used to create a declaration which is inaccessible:

    function show_alert()
      {
      label:
        {
        break label;
        var foo = 1;
        }
      console.log(foo);
      }
    

    but can be made accessible through string manipulation and the function constructor.

    References

    • ECMAScript-6 Annex B, Section 3.2: Labelled Function Declarations

    • Loop unrolling and completion-values in es6

    • The JavaScript Goto

    • Speed up your JavaScript, Part 1

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

Sidebar

Related Questions

Is there a way to create an array of Fixnums using ruby's % notation?
In D2D, is there a way to create a gradient brush which uses a
Got a simple question regarding twisted. I can create a trivial basic test with
This problem looks trivial, but I can't find the solution. When I create a
I am using a YML file to store trivial data. I can create yml:
Trivial using a for loop or each_with_index, just wondering if there was a better
I thought this would be trivial, but it isn't... I'm sure there is a
I'm not sure that there is a good way to do with with the
So it's trivial to create a Settings style table on the iPhone. The problem
A trivial use of PHP and frwite() to create/write to a text file. However,

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.