Function Jargons in JavaScript

Harshit Anand
2 min readAug 7, 2021

There are lots of terms associated with Functions in JavaScript. Although we are using all of them in our code on daily basis we are still unaware of them.
In this blog, we will get acquainted with all jargons associated with functions and which are important for interviews.

Function Statement
Consider the following code snippet:

function a(){
console.log("Hey there!");
}

The a() in the above snippet is a Function Statement.

Function Expression
Consider the following code snippet:

var name = function(){
console.log("Hey there!");
}

Above is a function expression. The only difference between the two is in terms of hoisting. In Execution Context when memory is allocated, a is treated as a function, and its code is also allocated in the memory. While b is treated as a variable and its value is undefined initially.

a();
b();
function a(){
console.log("a is called");
}
var b = function(){
console.log("b is called");
}
Output:
a is called
TypeError: b is not a function

Function Declaration
It is same as a function statement.

Anonymous Function
A function without a name is called an anonymous function. An anonymous function does not have its own identity. Anonymous functions are used in a place where functions are required as values. The following code will clear the explanation.

const num = [1,2,3,4,5];
var output = num.map(function(value){ // this function has no name
return value*2; // and is passed as a value
}); // to map() function.
Output:
[2,4,6,8,10]

Named Function Expression
The following code snippet is a Named Function Expression

var x = function abc(){
console.log("x is called");
}
x();

An important point to note here is that we can’t call abc(). It will throw ReferenceError as abc is not defined in the memory.

First Class Function
In JavaScript, functions are treated like any other variable. These functions can be passed as an argument to other functions, can be returned by other functions, and can be assigned as a value to any variable.

--

--