var b=1;
function someFunc(b) {
//here
}
I want to be able to reference the variable b that is defined outside the function. How can this be done in javascript?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You need to access it via the
global object, which iswindowin a browser andglobalin node.js for instance.Why ? Well, the such called Activation Object (in ES3) or the Lexical Environment Record (ES5) will overlap the variable name
b. So anytime a JS engine resolvesbit’ll stop at the first occurence, which is in its own Scope.