Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wrong output value written in Why Not to Use eval Section #358

Open
divyanshu-rawat opened this issue Jan 4, 2017 · 4 comments
Open

Wrong output value written in Why Not to Use eval Section #358

divyanshu-rawat opened this issue Jan 4, 2017 · 4 comments

Comments

@divyanshu-rawat
Copy link

In Why Not to Use eval Section

It is already mentioned that eval only executes in the local scope when it is being called directly and when the name of the called function is actually eval.

So, Here we are not calling it directly so it will not change the value of Global variable number.
Hence Global variable number will remain same i.e - 1

var number = 1;
function test() {
    var number = 2;
    var copyOfEval = eval;
    copyOfEval('number = 3');
    return number;
}
test(); // 2
number; // 3     (Here value of number will be 1 instead of 3)

Please Assign me this issue I want to contribute .

@peterjwest
Copy link
Collaborator

I've just tested this in node v6.4.0 and number ends up as 3, as expected. What version of JS/node are you using?

@divyanshu-rawat
Copy link
Author

divyanshu-rawat commented Jan 4, 2017

I am using node v7.3.0

@divyanshu-rawat
Copy link
Author

see !

output is 1

@peterjwest
Copy link
Collaborator

Actually if I run this from a file, I get the same result.
However running this in the node terminal or in Chrome produces the original result.

Javascript Garden doesn't technically cover node - and this seems to be a node feature.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants