Javascript Closure -Local variable nested function [duplicate]
问题 This question already has answers here : Why is my variable unaltered after I modify it inside of a function? - Asynchronous code reference (6 answers) Closed 3 years ago . I am trying to use a variable x defined inside a function P whose value I am trying to set in another function. It always comes undefined. I tried applying my mind to use closure but it's just going off my head. It does not gives me a string rather a object. The logic is as follows. function P(i){ var x; if(i!=null){ /