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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T20:00:52+00:00 2026-05-27T20:00:52+00:00

On a lot of browsers I’ve tested, JavaScript blocks actually return a value. You

  • 0

On a lot of browsers I’ve tested, JavaScript blocks actually return a value. You can test it out in any console:

for(var i = 0; i < 10; i++) {
    var sqrt = Math.sqrt(i);
    if(Math.floor(sqrt) === sqrt) {
        i;
    }
}

The “return” value is the last square number, that is, 9! But since it isn’t an expression I suppose, you can’t do this:

for(var i = 0; i < 10; i++) {
    ...
} + 5

That doesn’t work. It gives + 5, or 5, of course, because it’s a separate statement. Putting the loop in parentheses obviously fails, and if a block is in parentheses (e.g. ({f(); r}) – doesn’t work) it’s treated as an object and throws a syntax error.

One way to take advantage of the return value, as such, is to use eval:

eval('for(var i = 0; i < 10; i++) {var sqrt = Math.sqrt(i);if(Math.floor(sqrt) === sqrt) {i;}}') + 5; // 14

But I’m obviously not going to want to use that if eval is the only solution. Is there a way to use a block’s resultant value without using eval that I’m missing? I really like this feature 🙂

  • 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-27T20:00:52+00:00Added an answer on May 27, 2026 at 8:00 pm

    In JavaScript, statements return values of the Completion type (which is not a language type, but a specification type).

    The Completion type is used to explain the behaviour of statements
    (break, continue, return and throw) that perform nonlocal transfers of
    control. Values of the Completion type are triples of the form (type,
    value, target), where type is one of normal, break, continue, return,
    or throw, value is any ECMAScript language value or empty, and target
    is any ECMAScript identifier or empty.

    Source: http://es5.github.com/x8.html#x8.9

    So, eval() evaluates the program that has been passed in as source text. That program (like any JavaScript program) returns a Completion value. The second item in this Completion value (the “value” item) is returned by the eval() invocation.

    So, with eval you are able to retrieve the completion value of an JavaScript program. I am not aware of any other method to accomplish this…

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

Sidebar

Related Questions

Lot of googling did not help me! Are there any good dictionary web based
A lot of programming languages and frameworks do/allow/require something that I can't seem to
Of course, we have been witnessing a lot of browsers differences in rendering elements,
I know a lot of questions have been asked about HttpWebRequest. However, I can't
I'm working on my website and I'm testing it out in all browsers and
For a desktop-like app where a lot of interactions are needed between components, can
How do I emulate PHP-style __get() and __set() magic getter/setters in JavaScript? A lot
In non-IE browsers: The change event bubbles, so you can catch it when it
When a javascript error occures in IE (or in other browsers) you get a
When is __proto__ useful? A lot of browsers support it, but because not all

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.