Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How does the following functions return statement work

Tags:

javascript

function greaterThan(n) {
  return m => m > n;
}

I'm struggling to understand how this return statement works and what the 'm' variable actually does.

like image 598
Falko Avatar asked May 11 '18 05:05

Falko


People also ask

How does the return statement work?

A return statement ends the execution of a function, and returns control to the calling function. Execution resumes in the calling function at the point immediately following the call. A return statement can return a value to the calling function.

How does the return function work in Python?

The Python return statement is a special statement that you can use inside a function or method to send the function's result back to the caller. A return statement consists of the return keyword followed by an optional return value. The return value of a Python function can be any Python object.

How does return function work in C++?

return Statement (C++) Terminates the execution of a function and returns control to the calling function (or to the operating system if you transfer control from the main function). Execution resumes in the calling function at the point immediately following the call.

What does return function mean?

A return is a value that a function returns to the calling script or function when it completes its task. A return value can be any one of the four variable types: handle, integer, object, or string. The type of value your function returns depends largely on the task it performs.


1 Answers

greaterThan is the function which takes a parameter n and returns a function which takes parameter m. The returned function compares m and n and returns boolean value.

for Ex:

greaterThan(5)(4); // Returns false
like image 112
Laxmikant Dange Avatar answered Oct 20 '22 12:10

Laxmikant Dange