function inside function js code example
Example 1: function inside function javascript
function getFullName() {
return getName() + ' ' + getLastName();
function getName() {
return 'William';
}
function getLastName() {
return 'Wallace';
}
}
console.log(getFullName());
console.log(typeof getFullName);
console.log(typeof getName);
console.log(typeof getLastName);
Example 2: closures in javascript
function OuterFunction() {
var outerVariable = 100;
function InnerFunction() {
alert(outerVariable);
}
return InnerFunction;
}
var innerFunc = OuterFunction();
innerFunc();
Example 3: javascript closure function example
function makeFunc() {
var name = 'Mozilla';
function displayName() {
alert(name);
}
return displayName;
}
var myFunc = makeFunc();
myFunc();