Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

javascript Returning a Function

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

    // returning a function
    return displayName;
}

const g1 = greet('John');
console.log(g1); // returns the function definition
g1(); // calling the function
Comment

javascript return function

// Javascript double parentheses
// first function call result in a function that is called

function a() {
        return (name = 'b') => console.log(`I'm function ${name} produced by a()`);
}

a()();
a()('b2');

// result :
// I'm function b produced by a()
// I'm function b2 produced by a()
Comment

PREVIOUS NEXT
Code Example
Javascript :: disabled radio button 
Javascript :: appending an element to another element javascript 
Javascript :: how to increment counter button click in js 
Javascript :: javascript object array contains 
Javascript :: using .env in cra 
Javascript :: how to remove key value pair from object in javascript 
Javascript :: preview upload image js 
Javascript :: socket.io client send data node js server 
Javascript :: expose deployment nodeport command 
Javascript :: javascript key event 
Javascript :: object values 
Javascript :: how to know which button is clicked in jquery 
Javascript :: stop window.setinterval javascript 
Javascript :: how to show progress on ajax call 
Javascript :: require a json as a string 
Javascript :: javascript throw new error 
Javascript :: sort strings javascript alphabetically 
Javascript :: run function then empty it js 
Javascript :: mongoose multiple populate 
Javascript :: Immediately-Invoked Function javascript 
Javascript :: javascript .foreach 
Javascript :: nodemon watch extensions 
Javascript :: include js to js 
Javascript :: string normalize javascript 
Javascript :: javascript list has item 
Javascript :: object.entries 
Javascript :: Moment.js: Date between dates 
Javascript :: moment.add 
Javascript :: get element by xpath 
Javascript :: how to make a random if else in js 
ADD CONTENT
Topic
Content
Source link
Name
2+4 =