Skip to content

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

@divyanshu-rawat

Description

@divyanshu-rawat

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 .

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions