js function inside a function 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: closure in javascript
function makeFunc() {
var name = 'Mozilla';
function displayName() {
alert(name);
}
return displayName;
}
var myFunc = makeFunc();
myFunc();