0% found this document useful (0 votes)
4 views7 pages

Top 60 JavaScript Interview Questions FULL

The document provides a comprehensive list of the top 60 JavaScript interview questions and their answers, covering fundamental concepts such as data types, functions, asynchronous programming, and the DOM. Key topics include differences between various JavaScript constructs, event handling, and modern features like Promises and async/await. This resource serves as a valuable guide for individuals preparing for JavaScript-related interviews.

Uploaded by

bimanmaity2023
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views7 pages

Top 60 JavaScript Interview Questions FULL

The document provides a comprehensive list of the top 60 JavaScript interview questions and their answers, covering fundamental concepts such as data types, functions, asynchronous programming, and the DOM. Key topics include differences between various JavaScript constructs, event handling, and modern features like Promises and async/await. This resource serves as a valuable guide for individuals preparing for JavaScript-related interviews.

Uploaded by

bimanmaity2023
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 7

Top 60 JavaScript Interview Questions and Answers

1. What is JavaScript?

JavaScript is a high-level, interpreted programming language used to make web pages interactive. It is

primarily used for client-side development but is also used on the server-side with environments like Node.js.

2. What are the data types in JavaScript?

JavaScript has primitive types (String, Number, BigInt, Boolean, undefined, Symbol, null) and non-primitive

types (Object, Array, Function).

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

var is function-scoped, let and const are block-scoped. let allows reassignment, const does not. var can be

hoisted; let and const cannot be accessed before declaration.

4. What is hoisting?

Hoisting is JavaScript's behavior of moving declarations to the top of the scope before code execution.

5. What are arrow functions?

Arrow functions are a shorthand way to write functions. They do not have their own 'this', 'arguments', or

'super'.

6. What is a closure?

A closure is a function that retains access to its lexical scope, even when executed outside of that scope.

7. Explain 'this' keyword in JavaScript.

'this' refers to the object that is executing the current function. Its value changes depending on how the

function is called.

8. What is the difference between == and ===?

== checks for value equality with type coercion, === checks for both value and type equality.
Top 60 JavaScript Interview Questions and Answers

9. What is NaN?

NaN stands for 'Not-a-Number'. It is a value returned when a mathematical operation fails.

10. What is event bubbling and capturing?

Bubbling: event propagates from child to parent. Capturing: event propagates from parent to child.

11. What is the difference between null and undefined?

null is an assigned value, meaning 'no value'. undefined means a variable has been declared but not

assigned.

12. What are template literals?

Template literals are string literals allowing embedded expressions using backticks (``) and `${}`.

13. What is the use of the 'typeof' operator?

typeof returns a string indicating the type of the unevaluated operand.

14. What is a promise?

A Promise is an object representing the eventual completion or failure of an asynchronous operation.

15. What is async/await?

async/await is syntactic sugar over Promises for writing asynchronous code in a synchronous manner.

16. Explain the difference between call, apply, and bind.

call invokes a function with a given `this` and arguments. apply is the same but takes an array of arguments.

bind returns a new function with a bound `this`.

17. What is the DOM?

The DOM (Document Object Model) is a programming interface for HTML and XML documents representing

the page so that programs can change the document structure, style, and content.
Top 60 JavaScript Interview Questions and Answers

18. How do you clone an object in JavaScript?

Using Object.assign({}, obj) or the spread operator {...obj}.

19. What is the difference between deep copy and shallow copy?

A shallow copy copies only one level deep. A deep copy copies all levels and nested objects.

20. What are higher-order functions?

Functions that take other functions as arguments or return them.

21. What is a callback function?

A function passed into another function as an argument to be executed later.

22. What is the difference between synchronous and asynchronous code?

Synchronous code runs in sequence. Asynchronous code can run concurrently using events, callbacks, or

Promises.

23. What is an IIFE?

IIFE (Immediately Invoked Function Expression) is a function that runs as soon as it is defined.

24. What is a pure function?

A function that has no side effects and returns the same output given the same input.

25. What are JavaScript modules?

Modules allow encapsulation of code into reusable files using export/import syntax.

26. What is event delegation?

Event delegation allows you to add a single event listener to a parent element to manage events on its

children.
Top 60 JavaScript Interview Questions and Answers

27. What is a Set in JavaScript?

A Set is a collection of unique values.

28. What is a Map in JavaScript?

A Map is a key-value pair collection that maintains insertion order.

29. What is the difference between for...in and for...of?

for...in iterates over keys (property names), for...of iterates over values of iterable objects.

30. What are destructuring assignments?

Destructuring allows unpacking values from arrays or properties from objects into distinct variables.

31. What is the spread operator?

It expands elements of an array or object into individual elements.

32. What is rest parameter?

It allows a function to accept an indefinite number of arguments as an array.

33. How do you handle exceptions in JavaScript?

Using try...catch...finally blocks.

34. What is debounce and throttle in JavaScript?

Debounce limits function calls until after a pause. Throttle limits function calls to once per interval.

35. What is memory leak?

A memory leak occurs when memory is not released after it's no longer needed.

36. What are JavaScript data structures?


Top 60 JavaScript Interview Questions and Answers

Common structures include Arrays, Objects, Maps, Sets, and Typed Arrays.

37. What is JSON?

JSON (JavaScript Object Notation) is a format for storing and transporting data.

38. What is the difference between window and document?

window is the global object, document is a part of window that represents the DOM.

39. What are web APIs?

Browser-provided interfaces such as fetch API, DOM API, and localStorage.

40. What is the use of localStorage and sessionStorage?

localStorage persists data with no expiration. sessionStorage stores data for a session only.

41. How to check if a variable is an array?

Using Array.isArray(variable).

42. What is a promise chain?

Chaining `.then()` methods to execute async operations in sequence.

43. What is a ternary operator?

A shorthand if-else: `condition ? expr1 : expr2`.

44. What are tagged template literals?

Functions that process template literals, useful for custom formatting or escaping.

45. What is the use of Symbol in JavaScript?

Symbol is a unique and immutable data type used as object keys.


Top 60 JavaScript Interview Questions and Answers

46. What is a generator function?

A function that can be paused and resumed using `function*` and `yield`.

47. What is dynamic typing in JavaScript?

Variables can hold any data type and can change types at runtime.

48. How does JavaScript handle concurrency?

Through the event loop, which handles callbacks, promises, and asynchronous operations.

49. What is the event loop?

A mechanism that waits for and dispatches events or messages in a program.

50. How to convert a string to a number?

Using Number(), parseInt(), parseFloat(), or unary `+` operator.

51. What is the typeof null?

`object` - a long-standing bug in JavaScript.

52. How do you merge arrays?

Using concat(), spread operator [...arr1, ...arr2].

53. What is destructuring in functions?

Extracting values directly from objects/arrays passed as function arguments.

54. What is optional chaining?

Safely access nested properties: `obj?.prop?.subProp`.

55. What is the difference between slice and splice?


Top 60 JavaScript Interview Questions and Answers

slice returns a new array, splice modifies the original array.

56. How to prevent default behavior in an event?

Using `event.preventDefault()`.

57. What is the use of `new` keyword?

Used to create an instance of a user-defined object type or class.

58. What is prototypal inheritance?

A method by which objects inherit from other objects via the prototype chain.

59. What are falsy values in JavaScript?

`false`, `0`, `''`, `null`, `undefined`, `NaN`.

60. What is the difference between document.onload and DOMContentLoaded?

DOMContentLoaded fires when HTML is loaded; onload waits for all assets.

You might also like