Cosure Side effects

by SriSri M

JavaScript

function outerfn(fname){
	var name = 'My Name is';
  function innerfn(lname){
  // this inner function has access to the outer function's variables, including the parameter
  	console.log(name +' '+ fname +''+lname);
  }
  return innerfn;
}
var fullname = outerfn("Sri");//Outer fn is returned here
//Yet, the closure still has access to the outer function's variables and parameter
fullname('hassan');// My Name is Srihassan