Monday, 3 April 2017

Define const variable using eval()

When I try to define a variable using var, everything is working.

But defining it as const is not working as expected and the variable is undefined.

window.eval("var v = 5;");
document.body.innerHTML += window.v === undefined;

window.eval("const l = 5;");
document.body.innerHTML += window.l === undefined;

I have tested it on Chrome and Node.js. Am I missing something?

Thank you in advance!



via jooas

No comments:

Post a Comment