Closure example

Function inside a function can have access to variable scopes as well as the topmost params passed to it.

by KevinIsNowOnline

JavaScript

var introduce = function(firstname, lastname){
    var introLine = "Hi my name is ";
    
    function prepareName(){
     return introLine + firstname + lastname;   
    }
    
    return prepareName();
};

console.log(introduce("Kevin", "Bautista"));