Code belongs to javascriptissexy.com My question is why invoking mjName (\"Jackson\") returns \"This celebrity is Michael Jackson\"? Is it that second parameter given in ANY out
With this call
var mjName = celebrityName ("Michael");
you create a custom function, which has the firstName
variable bound to "Michael"
. This function is returned to you by celebrityName()
.
When you call that returned function again, you bind lastName
as well, which results in your output.
If you want to bind another first name, you have to call celebrityName()
again.
var michaelName = celebrityName( "Michael" );
var davidName = celebrityName( "David" );
michaelName( "Jackson" ); // yields "This celebrity is Michael Jackson"
davidName( "Duchovny" ); // yields "This celebrity is David Duchovny"