First-Class Functions Interview Questions in JavaScript
First-class functions are a core interview topic. Here are the most asked questions with answers.
First-Class Functions Interview Questions in JavaScript
First-class functions are a core interview topic. Here are the most asked questions with answers.
Q1: What does it mean that functions are first-class citizens in JavaScript?
Functions are treated like any other value: they can be assigned to variables, passed as arguments, returned from other functions, stored in data structures, and have a type (typeof is "function").
Q2: What is the difference between a function statement and a function expression?
A function statement (declaration) is hoisted with its full body and can be called before the line. A function expression is assigned to a variable, which is hoisted (undefined with var, TDZ with let/const) but the function body is only assigned at the line.
Q3: What is an anonymous function?
A function without a name. It is often assigned to a variable (const greet = function() {}) or used as a callback. The variable has a name, but the function itself does not.
Q4: What is a named function expression?
const greet = function sayHi(name) { return `Hello, ${name}`; }; `` `sayHi` is only visible inside the function. It is useful for recursion and produces better stack traces. ### Q5: Can you pass a function as an argument? Give an example. ```js [1, 2, 3].map((n) => n * 2); // [2, 4, 6] setTimeout(() => console.log("hi"), 1000); button.addEventListener("click", () => console.log("clicked")); `` ### Q6: Can a function return another function? Give an example. ```js function multiplier(factor) { return (n) => n * factor; } const double = multiplier(2); double(5); // 10 `` ### Q7: What is the difference between parameters and arguments? Parameters are the variable names in the function definition. Arguments are the actual values passed when calling the function. ### Q8: What is a higher-order function? A function that takes a function as an argument, returns a function, or both. Examples: `map`, `filter`, `reduce`, `compose`, `curry`, `setTimeout`. ### Q9: Do arrow functions have their own `this` and `arguments`? No. Arrow functions inherit `this` from their lexical scope. They do not have their own `arguments` object (reference the enclosing function's). Use rest parameters (`...args`) in arrows. ### Q10: What is `typeof` for a function? `"function"`. Functions are a distinct type, but under the hood they are callable objects. ### The Takeaway First-class function interview questions test: the definition (functions as values), function statements vs expressions (hoisting), anonymous vs named functions, passing and returning functions, parameters vs arguments, higher-order functions, arrow function differences, and `typeof` for functions.
Functions are treated like any other value: assignable to variables, passable as arguments, returnable from functions, storable in data structures, and typeof is 'function'.
A function statement is hoisted with its full body (callable before the line). A function expression is assigned to a variable (variable hoisted only, function body assigned at the line).
A function that takes a function as an argument, returns a function, or both. Examples include map, filter, reduce, compose, curry, and setTimeout.
No. Arrow functions inherit this from their lexical scope (cannot be changed by call, apply, or bind). They do not have their own arguments object; use rest parameters (...args) instead.
Parameters are the variable names listed in the function definition. Arguments are the actual values passed to the function when it is called.
Ready to master React completely?
Want to upskill yourself, crack your next interview, and get your dream job? Join our comprehensive course to dive deeper with high-quality video tutorials, solve interview questions, and a premium community.
Master React
Want to upskill yourself, crack your next interview, and get your dream job? Join our comprehensive course.

