Answered by : splendid-stork-ojbwdni7iz8j
function test(arg){ return arg;
}
Source : | Last Update : Mon, 27 Apr 20
Answered by : eric-tam
function test()
{ return function x() { return "xxxxxxxx" }
}
console.log(test())
//[Function: x()]
console.log(test()())
//xxxxxxxx
Source : | Last Update : Mon, 08 Aug 22
Answered by : intra
/* The return statement ends a function immediately at the
point where it is called. */
function counter() { for (var count = 1; count < 5 ; count++) { console.log(count + 'A'); if (count === 3) return; // ends entire counter function console.log(count + 'B'); } console.log(count + 'C'); // never appears
}
counter();
// 1A
// 1B
// 2A
// 2B
// 3A
Source : https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/return | Last Update : Thu, 17 Mar 22
Answered by : samer-saeid
// program to add two numbers
// declaring a function
function add(a, b) { return a + b;
}
// take input from the user
let number1 = parseFloat(prompt("Enter first number: "));
let number2 = parseFloat(prompt("Enter second number: "));
// calling function
let result = add(number1,number2);
// display the result
console.log("The sum is " + result);
Source : | Last Update : Sat, 28 May 22
Answered by : frightened-flamingo-5h7v1gyqtsrg
// 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()
Source : | Last Update : Thu, 13 Oct 22
Answered by : doubtful-dunlin-lisztgybsrxl
An Example of a return function
function add15(number) { let newNumber = number + 15; return newNumber;
}
let fifteen = add15(5);
console.log(fifteen);
Source : | Last Update : Wed, 24 Nov 21
Answered by : fancy-fly-779ev7frbckp
//The return statement ends function execution,
//and specifies a value to be returned to the function caller.
function getRectArea(width, height) { if (width > 0 && height > 0) { return width * height; } return 0;
}
console.log(getRectArea(3, 4));
// expected output: 12
console.log(getRectArea(-3, 4));
// expected output: 0
Source : | Last Update : Fri, 21 Oct 22
Answered by : ainul-sakib
// --- The following return statements all break the function execution: ---
return;
return true;
return false;
return x;
return x + y / 3;
Source : https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/return#Automatic_Semicolon_Insertion | Last Update : Wed, 13 Jan 21