title: Can I run ECMAScript 6 from Java 9 Nashorn engine
body: <p>Java 9 now includes ECMAScript 6 support, as claimed by <a href="https://www.oracle.com/corporate/features/nashorn-javascript-engine-jdk9.html" rel="noreferrer">this article</a>. However, it doesn't explain how to run it from Java with <a href="https://docs.oracle.com/javase/9/docs/api/javax/script/ScriptEngine.html" rel="noreferrer">ScriptEngine</a>. The linked Java magazine also doesn't explain it. The article says the following:</p>
  
  <blockquote>
    <p>To activate ES6 support, use <code>--language=es6</code> on the command line.</p>
  </blockquote>
  
  <p>This does work with <code>jjs</code>, but I can't find a way how to enable this from Java code. To test it, I used the following code:</p>
  
  <pre><code>import javax.script.ScriptEngine;
  import javax.script.ScriptEngineManager;
  import javax.script.ScriptException;
  ...
  ScriptEngine engine = new ScriptEngineManager().getEngineByMimeType("application/javascript");
  try {
      engine.eval("const a = 20;");
  } catch (ScriptException e) {
      e.printStackTrace();
  }
  </code></pre>
  
  <p>It fails with the following exception:</p>
  
  <pre><code>javax.script.ScriptException: &lt;eval&gt;:1:0 Expected an operand but found const
  const a = 20;
  ^ in &lt;eval&gt; at line number 1 at column number 0
      [STACK TRACE OMITTED]
  </code></pre>
  
  <p>I've tried to list all available <a href="https://docs.oracle.com/javase/9/docs/api/javax/script/ScriptEngineFactory.html" rel="noreferrer">ScriptEngineFactories</a> with this code:</p>
  
  <pre><code>import java.util.List;
  import javax.script.ScriptEngineFactory;
  import javax.script.ScriptEngineManager;
  ...
  List&lt;ScriptEngineFactory&gt; factories = new ScriptEngineManager().getEngineFactories();
  for (ScriptEngineFactory factory : factories) {
      System.out.println("-----------------------");
      System.out.println(factory.getLanguageName());
      System.out.println(factory.getLanguageVersion());
  }
  </code></pre>
  
  <p>This outputs just the following:</p>
  
  <pre><code>-----------------------
  ECMAScript
  ECMA - 262 Edition 5.1
  </code></pre>
  
  <p>Does this mean I can't run ECMAScript 6 from Java and only using <code>jjs</code>? Or is there something I have missed?</p>
  
  <p>Thanks beforehand.</p>