javascript functions interview questions including closures, scope, IIFE, prototypes, and currying. Essential for frontend developers preparing for technical interviews in 2025. Javascript functions interview questions


🚀 Javascript functions interview questions

16. What is a Closure in JavaScript?

Answer:
A closure is the combination of a function and its lexical environment. It gives access to an outer function’s scope from an inner function even after the outer function has returned.

function outer() {
  let count = 0;
  return function inner() {
    count++;
    return count;
  };
}

const counter = outer();
console.log(counter()); // 1
console.log(counter()); // 2

17. What is Scope in JavaScript?

Answer:
Scope determines the accessibility (visibility) of variables:

  • Global Scope
  • Function Scope
  • Block Scope (with let and const)
let a = 10; // Global Scope

function foo() {
  let b = 20; // Function Scope
  if (true) {
    let c = 30; // Block Scope
  }
}

18. What is the difference between null and undefined?

Answer:

  • undefined: A variable declared but not assigned a value.
  • null: An assignment value that represents no value.
let a;
console.log(a); // undefined

let b = null;
console.log(b); // null

19. What is an IIFE (Immediately Invoked Function Expression)?

Answer:
An IIFE is a function that runs as soon as it is defined. It avoids polluting the global scope.

(function () {
  console.log("IIFE executed");
})();

20. What is the Prototype in JavaScript?

Answer:
All JavaScript objects inherit properties and methods from a prototype. This allows inheritance and method sharing.

function Person(name) {
  this.name = name;
}

Person.prototype.greet = function () {
  return `Hello, ${this.name}`;
};

const john = new Person("John");
console.log(john.greet()); // Hello, John

21. Explain prototypal inheritance.

Answer:
JavaScript uses prototypal inheritance to share properties between objects. Objects inherit directly from other objects using their prototype chain.


22. What is Currying in JavaScript?

Answer:
Currying is a function that returns another function until all arguments are provided.

function add(a) {
  return function (b) {
    return function (c) {
      return a + b + c;
    };
  };
}

console.log(add(1)(2)(3)); // 6

23. What is memoization in JavaScript?

Answer:
Memoization is an optimization technique that caches the results of function calls.

function memoize(fn) {
  const cache = {};
  return function (n) {
    if (cache[n]) return cache[n];
    cache[n] = fn(n);
    return cache[n];
  };
}

const factorial = memoize(function(n) {
  return n <= 1 ? 1 : n * factorial(n - 1);
});

24. What are higher-order functions?

Answer:
Functions that take other functions as arguments or return functions.

function operate(fn, a, b) {
  return fn(a, b);
}

console.log(operate((x, y) => x + y, 5, 3)); // 8

25. Explain the concept of this in JavaScript.

Answer:
this refers to the object from which the function was called. It varies based on context:

  • In global scope: this is window (in browsers)
  • In method: this is the object
  • In arrow functions: this is lexically bound
const obj = {
  name: 'Alice',
  greet() {
    return `Hi, I'm ${this.name}`;
  }
};

⛓️ More Topics Coming in Part 3

Javascript functions interview questions In Part 3, we’ll cover:

  • Object-Oriented JavaScript
  • Functional Programming
  • DOM Manipulation
  • Event Handling
  • Error Handling
  • Built-in Methods
  • Array/Object Methods

javascript basics interview questions Part 1: Mastering the Basics

Javascript functions interview questions
Part 3, diving into OOP and functional programming in JavaScript.

Share.

Welcome to Dastgeertech Studio! We are a dynamic and innovative tech company based in Lahore, Pakistan. At Dastgeertech Studio, we are dedicated to providing cutting-edge technology solutions tailored to meet the unique needs of our clients.

Leave a ReplyCancel reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Discover more from DastgeerTech Studio

Subscribe now to keep reading and get access to the full archive.

Continue reading

Exit mobile version