DEV Community

loading...
Cover image for First-Class Function interview question

First-Class Function interview question

Nikhil Bobade
I am Frontend Developer, currently living in Mumbai, India. My interests range from technology to design. Currently learning MEAN and Data Structure.
・1 min read

Why we use the first-class function that really needed in JavaScript.

1.A simple definition of the first-class function is a function that can be passed as an argument to another function.

2.And also returned by another function in JavaScript.

3.or also can be assigned the variable to function.

Some Example with the first-class function:-

function with a variable

const foo = function() {
   console.log("foobar");
}
// Invoke it using the variable
foo();
Enter fullscreen mode Exit fullscreen mode

A returned a function using the first-class function

function sayHello() {
   return function() {
      console.log("Hello!");
   }
}
sayHello()();
Enter fullscreen mode Exit fullscreen mode

Thank you!

Discussion (0)

Forem Open with the Forem app