Sitemap

Javascript Interview Q & A

4 min readAug 14, 2026

--

01. What is Javascript ?

JavaScript is a high-level, interpreted programming language used to create interactive and dynamic web pages.

It is one of the three core technologies of web development:

  • HTML → Defines the structure of a web page.
  • CSS → Controls the appearance and layout.
  • JavaScript → Enhance interactivity and functionality.

02. What are the different data types in Javascript ?

JavaScript Data Types are the different kinds of values that can be stored in variables. JavaScript data types are generally divided into two categories:

  1. Primitive data types — string, number, boolean, null, undefined, BigInt, and symbol.
  2. Non-primitive (Reference) data types- Object, Array, Function

03. What is the difference between var, let and const?

var, let, and const are used to declare variables in JavaScript, but they behave differently. var is function-scoped and allows a variable to be redeclared and updated. let is block-scoped and allows a variable to be updated but not redeclared within the same scope. const is also block-scoped, but its value cannot be reassigned after it is declared. In modern JavaScript, let and const are preferred because they provide better control over variable scope and help prevent programming errors.

04. What is Hoisting in Javascript?

Hoisting is a JavaScript behavior in which variable and function declarations are moved to the top of their scope during execution. This means that functions can be used before they are declared, while variables declared with var are initialized with undefined. Variables declared with let and const are also hoisted, but they cannot be accessed before their declaration.

05. What are closures in JavaScript? Provide an example and explain their practical use cases.

A closure is the combination of a function and the lexical environment in which it was created, allowing the function to access variables from its surrounding scope even after that scope has finished executing. (Corrected according to the official MDN definition.

function counter() {
let count = 0;

return function () {
count++;
return count;
};
}

const myCounter = counter();

console.log(myCounter()); // 1
console.log(myCounter()); // 2
console.log(myCounter()); // 3

Practical uses: Closures are commonly used for data privacy, maintaining state, callbacks, event handlers, and creating functions with customized behavior.

06. What is an arrow function in Javascript?

An arrow function is a shorter way to write a function in JavaScript. It is introduced using the => symbol and is commonly used for simple functions and callbacks.

07. What is the this keyword in JavaScript?

Get Achini Ishani’s stories in your inbox

Join Medium for free to get updates from this writer.

The this keyword in JavaScript refers to the object that is currently executing the function.

const person = {
name: "John",
greet: function() {
console.log(this.name);
}
};

person.greet(); // John

08. What is event bubbling in Javascript?

Event bubbling is when an event starts from the target element and then moves upward through its parent elements. For example, if you click a button inside a <div>, the click event can first occur on the button and then bubble up to the <div>, <body>, and so on.

09. What is event delegation in Javascript?

Event delegation is a technique where we attach a single event listener to a parent element instead of adding separate listeners to each child element. It works using event bubbling and is useful for improving performance, especially when there are many child elements.

10. Explain the purpose and usage of async and await keywords in JavaScript.

async and await are used in JavaScript to handle asynchronous operations such as API calls. An async function always returns a Promise, while await pauses the execution of the function until the Promise is completed. They make asynchronous code easier to read and understand.

async function getData() {
const response = await fetch("https://api.example.com/data");
const data = await response.json();
console.log(data);
}

11. What is the DOM in the Javascript?

DOM (Document Object Model) is a representation of an HTML webpage as a tree of objects. JavaScript uses the DOM to access, change, add, or remove HTML elements and their content dynamically.

12. What is JSON? And how is it used in Javascript?

JSON (JavaScript Object Notation) is a lightweight format used to store and exchange data between a client and a server. In JavaScript, JSON.stringify() converts an object into a JSON string, and JSON.parse() converts a JSON string back into an object.

13. What are higher-order functions in JavaScript? Give examples of higher-order functions and explain their purpose.

Higher-order functions are functions that take another function as an argument or return a function as a result. Common higher-order functions include map(), filter(), reduce(), and forEach(). They help simplify operations on arrays and make code cleaner and more readable.

14. What is debouncing in Javascript?

Debouncing is a technique that delays the execution of a function until a certain amount of time has passed without the event occurring again. It is commonly used for search boxes, input fields, and window resizing to avoid running a function too many times.

15. What is the difference between map and forEach?

The main difference is that map() returns a new array, while forEach() does not return a new array. map() is used when you want to transform each element and create a new array, whereas forEach() is mainly used to perform an action on each element.

const numbers = [1, 2, 3];

const result = numbers.map(n => n * 2);
console.log(result); // [2, 4, 6]

numbers.forEach(n => console.log(n)); // 1 2 3

In short: Use map() to create a new array and forEach() to simply perform an action on each item.

References

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Closures?utm_source=chatgpt.com

--

--