32

I'm toying with let in Node v0.10.12. Using the --harmony flag the following code produces a syntax error:

for (let i = 0; i < 2; i += 1) {
    console.log('i', i);
}

SyntaxError: Illegal let declaration outside extended mode

However, if I also use the --use-strict flag, then the code runs as expected.

Why is a syntax error thrown when just using the --harmony flag? What is extended mode? What is the connection with strict mode?

2
  • Is ECMAscript still a used term? Jun 22, 2013 at 19:05
  • 12
    @bwheeler96 It is the official name of the language standard
    – HBP
    Jun 22, 2013 at 19:08

2 Answers 2

15

It looks like "extended mode" was removed from the current development version of the harmony spec on February 27, 2012, but there's a description of what it was supposed to be in a few older ones (this one is from January 16, 2012):

10.1.2 Extended Code

Extended code is any code contained in an ECMAScript Program syntactic unit that contains occurrences of lexical or syntactic productions defined subsequent to the Fifth Edition of the ECMAScript specification. Code is interpreted as extended code in the following situations:

  • Global code is extended global code if it is contained in an ECMAScript Program syntactic unit that has been designated as an extended Program unit in an implementation defined manner or if ???.

  • Eval code is extended eval code if the call to eval is a direct call (see 15.1.2.1.1) to the eval function that is contained in extended mode code or if it begins with ???.

  • Function code that is part of a FunctionDeclaration, FunctionExpression, or accessor PropertyAssignment is extended function code if its FunctionDeclaration, FunctionExpression, or PropertyAssignment is contained in extended mode code or if the function code begins with ???.

  • Function code that is supplied as the last argument to the built-in Function constructor is strict function code if the last argument is a String that when processed as a FunctionBody begins with ???.

The term “strict code” is used to designate both actual strict mode code and extended code while the term “extended code” only designates actual extended code. The term “base code” is used to designate code that is not extended code.

As for the connection with strict mode, that seems to be specific to V8's (experimental) implementation. Here's what the changelog for revision 10062, which introduced the --harmony flag, says:

This CL introduces a third mode next to the non-strict (henceforth called 'classic mode') and 'strict mode' which is called 'extended mode' as in the current ES.next specification drafts. The extended mode is based on the 'strict mode' and adds new functionality to it. This means that most of the semantics of these two modes coincide.

The 'extended mode' is entered instead of the 'strict mode' during parsing when using the 'strict mode' directive "use strict" and when the the harmony-scoping flag is active. This should be changed once it is fully specified how the 'extended mode' is entered.

10

How to obtain harmony in your node.js

The --harmony flag enables ES Harmony features. it seems that --harmony enables new ECMA features in the language, based on the v8, proxies, weak maps, sets, maps, typeof semantics, and block scoping are available when this flag is being used and these are extended features and after extending these features you can use for example let (for block scoping) with strict mode enabled only because it's based on it, otherwise it will throw

SyntaxError: Illegal let declaration outside extended mode.

Extended Mode : When you are using new ECMA features (ECMAScript 5), you are in the extended mode of the language and in this mode ECMAScript’s new features (extended code) and syntax could be used only in strict mode

Concept of “extended code” that means code that may use new Es.next syntax.

Harmony :

"Harmony" is the name of the major upgrade to JavaScript due to arrive by the end of 2013. In 2008, after much controversy, the ECMA Technical Committee 39, that had been charged with creating the next generation of JavaScript, agreed to work together on a "Harmony" update to JavaScript and it has been in development since then. A number of the proposed features of Harmony are supported by Google's implementation. These include block scoped bindings and the addition of the let keyword, efficient maps and sets to remove the need to "abuse objects as dictionaries", weak maps for garbage collectable key/value tables and proxies which can simulate any JavaScript object or function to enable customisation.

Some good reads here and hear. Also from Chromium Blog.

Also from Paul Irish :

François Beaufort (originally shared): A new flag named Enable Experimental JavaScript appeared in the chrome://flags page of the last Chromium build. This flag enables web pages to use experimental JavaScript features.

To use extended mode/harmony features now in Chrome we have to enable this and we can enable this by navigating to chrome://flags and can toggle (enable/disable) on "Experimental JavaScript features".

10
  • 1
    The question is about --use-strict. Why does --harmony alone throw a syntax error?
    – Blender
    Jun 22, 2013 at 18:36
  • 1
    Well, what is extended mode and what does it have to do with strict mode?
    – Blender
    Jun 22, 2013 at 18:38
  • Note: with V8, at least for the time being, you can use let with strict mode only, otherwise it will complain SyntaxError: Illegal let declaration outside extended mode.
    – The Alpha
    Jun 22, 2013 at 18:39
  • @Blender, The Experimental JavaScript features, read this and other links in the answer.
    – The Alpha
    Jun 22, 2013 at 18:42
  • I get what you're trying to say, but this is more of a "why" question. Why do you require strict mode? What is extended mode?
    – Blender
    Jun 22, 2013 at 18:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.