Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

javascript nested functions

/*
 * A nested function is a function within another function.
 * A nested function is local, meaning it can only be accessed
 * by code within that same function scope.
 */
function globalFunction() {
	function localFunction() {
		return "Hello world!";
	}
	return localFunction();
}
console.log(globalFunction()); // -> "Hello world!"
console.log(localFunction()); // -> Uncaught ReferenceError: localFunction is not defined
 
PREVIOUS NEXT
Tagged: #javascript #nested #functions
ADD COMMENT
Topic
Name
1+8 =