JavaScript eval () and const

I just stumbled upon a strange JavaScript error using Mozilla Rhino as a JavaScript engine.

The error message is displayed in this line of the script:

eval("const a = 5;");

Error:

TypeError: redeclaration of var a.

I would expect this error if the line is executed several times, but it is executed only once, since this one line is the whole program.

Can someone explain why this error occurs?

+5
source share
1 answer

There is no const type in javascript. You will have to use this instead

eval ("var a = 5;");

-1
source

All Articles