DEV Community

Cover image for First Class Functions
Mugendi Njue
Mugendi Njue

Posted on

First Class Functions

Today i learned that JavaScript is a lightweight, interpreted,or JIT(Just In Time) compiled language with first class functions.
What are first class functions? Well a programming language is said to have first class functions when functions in that programming language are treated like any other variable.Example

// Assigning a variable to a function
const foo = () => {
// Invoking the function
Enter fullscreen mode Exit fullscreen mode

You can also have a function that returns another function, for example

const sayHello = () => {
   return () => {
// Method 1 of function invoking
const myFunc = sayHello();
// Method 2 of function invoking
Enter fullscreen mode Exit fullscreen mode

Functions that return other functions are called Higher-Order Functions.

Top comments (0)