JDK-8057691 : Nashorn: let & const declarations are not shared between scripts
The Version table provides details related to the release that this issue/RFE will be addressed.
Unresolved : Release in which this issue/RFE will be addressed. Resolved: Release in which this issue/RFE has been resolved. Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.
I tried with jjs
$ jjs --language=es6
jjs> var x = 2;
jjs> let a = 1;
<shell>:1 ReferenceError: "a" is not defined
I noticed this as well. The thing is that in the shell we handle each line of input as separate script, and the lexically defined variables are only defined in that script. In order to make them visible throughout a shell session we'd have to preserve that per-script scope somehow.
I noticed that this works in V8 shell so they must do something to "connect" the input lines like reusing the per-script scope.
I also noticed that the same problem occurs for normal vars in -strict mode:
$ jjs -strict
jjs> var x = 123
<shell>:1 ReferenceError: "x" is not defined