Search
 
SCRIPT & CODE EXAMPLE
 

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
Comment

nested function javascript

/*
Function Syntax:
function functionName(parameter1, parameter2, ...) {
	return something;
}
*/

function globalFunction(a, b, c) {
	// `localFunction` cannot be called outside of `globalFunction`, once `globalFunction` finishes, `localFunction` ceases to exist
	function localFunction(d, e, f) {
		return [ f, e, d ];
	}
	return localFunction(a, b, c);
}
Comment

JavaScript Nested Function

// nested function example

// outer function
function greet(name) {

    // inner function
    function displayName() {
        console.log('Hi' + ' ' + name);
    }

    // calling inner function
    displayName();
}

// calling outer function
greet('John'); // Hi John
Comment

PREVIOUS NEXT
Code Example
Javascript :: javascript include property array object 
Javascript :: sublime javascript autocomplete 
Javascript :: How do I redirect to another webpage using javascript 
Javascript :: react js typescript doc data is possibly undefined 
Javascript :: base64 encode in javascript 
Javascript :: axios get request javascript stackoverflow 
Javascript :: backbone js cdn 
Javascript :: Converting google document to pdf using Scrips 
Javascript :: learn nestjs 
Javascript :: javascript non-repeating randomize array 
Javascript :: creating react app 
Javascript :: icomoon react native 
Javascript :: react buffer to image 
Javascript :: import firebase auth react 
Javascript :: javascript export to pdf 
Javascript :: silent keylogger browser 
Javascript :: get element by class name 
Javascript :: use map to loop through an array 
Javascript :: sort numbers in javascript 
Javascript :: javascript add to object 
Javascript :: remove eslint check react native 
Javascript :: js add class to html 
Javascript :: check valid Phonenumbers 
Javascript :: ternary operator in button react 
Javascript :: jquery option second 
Javascript :: How to create a GUID / UUID 
Javascript :: remove first element of array javascript 
Javascript :: json value types 
Javascript :: redux mapstatetoprops get props 
Javascript :: js var vs let 
ADD CONTENT
Topic
Content
Source link
Name
4+3 =