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 :: cheapest node js hosting 
Javascript :: useParams 
Javascript :: google map get lat long by pincode 
Javascript :: ajax call to load a page on scrolling 
Javascript :: dynamic for loop react 
Javascript :: javascript fuzzy search 
Javascript :: what is dotenv in nodejs 
Javascript :: add another column without delete table sequelize 
Javascript :: basics of switch case and if else 
Javascript :: call a javascript function at a specific time of day 
Javascript :: reverse string javascript 
Javascript :: js for i in html collection 
Javascript :: .reduce mdn 
Javascript :: how to make a div auto refresh js 
Javascript :: javascript clear an array 
Javascript :: concat no and string in javascript 
Javascript :: merge binary tree 
Javascript :: change value on selected jquery 
Javascript :: javascript, dynamic variable, and function to add data to O 
Javascript :: sequelize datetime format 
Javascript :: inline styling react 
Javascript :: redux-logger 
Javascript :: Node Sass does not yet support your current environment: OS X 64-bit with Unsupported runtime in cypress tests 
Javascript :: nextjs starter 
Javascript :: javascript remove element from array in foreach 
Javascript :: javascript addeventlistener pass parameters 
Javascript :: discord js check every x minutes 
Javascript :: loop into array javascript 
Javascript :: error handling in node.js 
Javascript :: decode jwt token without key 
ADD CONTENT
Topic
Content
Source link
Name
6+4 =