Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...

What is a “closure” in JavaScript? Provide an example

Answer Posted / hrpatelsoft@gmail.com

var globalVar = "xyz";

(function outerFunc(outerArg) {
var outerVar = 'a';

(function innerFunc(innerArg) {
var innerVar = 'b';

console.log(
"outerArg = " + outerArg + "
" +
"innerArg = " + innerArg + "
" +
"outerVar = " + outerVar + "
" +
"innerVar = " + innerVar + "
" +
"globalVar = " + globalVar);

})(456);
})(123);

Is This Answer Correct ?    0 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Is javascript client side or server side?

988


What output will this program produce System.out.println(x+"+"+y+"="+(x+));

2094


What is javascript in simple terms?

1010


Why is my javascript function not defined?

1037


How do you define a class and its constructor?

1031


How can an HTMLCollection be traversed?

1094


What is meant by object oriented programming?

959


How to add multiple functions in javascript?

948


What is the reason for wrapping the entire content of a javascript source file in a function book?

1075


Why do we need currying?

905


How to create an input box?

1198


Is everything in javascript asynchronous?

951


Explain the working of timers in JavaScript? Also elucidate the drawbacks of using the timer, if any?

1042


What is the use of blur function in JavaScript?

1083


Entire content of a JavaScript source file in a function block?

1123