0% found this document useful (0 votes)
2 views

Advanced_JavaScript_Questions_Full (1)

The document contains 50 advanced JavaScript questions and detailed answers covering key concepts such as variable scoping, closures, the event loop, promises, and functional programming. It also discusses modern JavaScript features introduced in ES6+, including modules, async/await, and the Temporal API. Each question provides a concise explanation, making it a useful resource for understanding advanced JavaScript topics.

Uploaded by

sujeetnangare
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

Advanced_JavaScript_Questions_Full (1)

The document contains 50 advanced JavaScript questions and detailed answers covering key concepts such as variable scoping, closures, the event loop, promises, and functional programming. It also discusses modern JavaScript features introduced in ES6+, including modules, async/await, and the Temporal API. Each question provides a concise explanation, making it a useful resource for understanding advanced JavaScript topics.

Uploaded by

sujeetnangare
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

50 Advanced JavaScript Questions with Detailed Answers

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


var is function-scoped and can be redeclared; let is block-scoped and cannot be redeclared; const is
block-scoped and immutable after initialization.

2. What is closure in JavaScript?


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

3. What is the event loop in JavaScript?


The event loop is a mechanism that handles asynchronous operations by pushing callbacks from
the event queue to the call stack.

4. What is hoisting in JavaScript?


Hoisting moves variable and function declarations to the top of their containing scope before
execution.

5. What is the difference between == and === in JavaScript?


== checks for value equality with type coercion, whereas === checks for both value and type
equality.

6. What is a Promise in JavaScript?


A Promise represents a value that may be available now, or in the future, or never, and it has states:
pending, resolved, or rejected.

7. What are async and await in JavaScript?


async makes a function return a Promise, and await pauses execution until the Promise resolves.

8. What are arrow functions, and how are they different from regular functions?
Arrow functions have a shorter syntax and do not have their own this, arguments, or prototype.

9. What is the difference between null and undefined?


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

10. What is the difference between function declaration and function expression?
Function declarations are hoisted, whereas function expressions are not.

11. What is the difference between call, apply, and bind?


call invokes a function with a specific 'this' and arguments, apply is similar but takes an array of
arguments, and bind returns a new function with 'this' set.

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


An IIFE is a function that executes immediately after its definition, often used to create a local
scope.

13. What is a higher-order function?


A higher-order function is a function that takes another function as an argument or returns a
function.

14. What is the difference between spread and rest operators?


The spread operator (...) expands elements, whereas the rest operator (...) collects them into an
array.

15. What is debouncing and throttling?


Debouncing delays execution until after a pause in activity, whereas throttling limits execution to a
fixed rate.

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


A shallow copy copies object references, whereas a deep copy clones objects recursively to avoid
reference issues.

17. What are JavaScript generators?


Generators are functions that can be paused and resumed using the 'yield' keyword.

18. What is the difference between synchronous and asynchronous programming?


Synchronous code executes sequentially, whereas asynchronous code allows non-blocking
execution using callbacks, promises, or async/await.

19. What is memoization in JavaScript?


Memoization is an optimization technique that caches function results to improve performance.

20. What are weakMap and weakSet in JavaScript?


WeakMap and WeakSet store weakly referenced keys, allowing garbage collection when keys are
no longer needed.

21. What is event delegation in JavaScript?


Event delegation is a technique where a parent element handles events from child elements,
improving performance by reducing event listeners.

22. What is the difference between localStorage, sessionStorage, and cookies?


localStorage stores data permanently, sessionStorage clears data when the session ends, and
cookies store small data with expiration and can be sent with HTTP requests.
23. What is prototype inheritance in JavaScript?
Prototype inheritance allows objects to inherit properties and methods from other objects via the
prototype chain.

24. What is the difference between map, filter, and reduce?


map transforms elements, filter selects elements based on a condition, and reduce accumulates
values into a single result.

25. How does the 'this' keyword work in JavaScript?


'this' refers to the execution context and can vary based on how a function is called (global, object
method, event handler, etc.).

26. What is the difference between synchronous and asynchronous iterators?


Synchronous iterators return values immediately, whereas asynchronous iterators use Promises and
can fetch data over time.

27. What is the difference between Object.freeze() and Object.seal()?


Object.freeze() makes an object immutable, while Object.seal() prevents adding or removing
properties but allows modification of existing ones.

28. What is the difference between deep cloning and shallow cloning?
Shallow cloning copies object references, while deep cloning duplicates nested objects to create
independent copies.

29. What is the difference between setTimeout and setInterval?


setTimeout executes a function once after a delay, while setInterval repeatedly calls a function at
specified intervals.

30. What are JavaScript WeakRefs?


WeakRefs allow weak references to objects, which do not prevent garbage collection.

31. What is optional chaining in JavaScript?


Optional chaining (?.) prevents errors by safely accessing deeply nested object properties.

32. What is nullish coalescing (??) in JavaScript?


The nullish coalescing operator returns the right-hand value only if the left-hand value is null or
undefined.

33. What is the difference between destructuring and spreading?


Destructuring extracts values from objects/arrays, while spreading expands them into individual
elements.

34. What is tail call optimization?


Tail call optimization improves recursion performance by reusing stack frames when the last
operation is a function call.

35. What are modules in JavaScript?


Modules allow code reuse and encapsulation, using export/import statements in ES6+.

36. What is a singleton in JavaScript?


A singleton ensures a single instance of an object is created and shared across the application.

37. What are JavaScript mixins?


Mixins allow objects to inherit behavior from multiple sources, promoting code reuse.

38. What is the Temporal API in JavaScript?


The Temporal API provides a modern way to work with dates and times, improving accuracy over
Date objects.

39. What are tagged template literals?


Tagged template literals allow parsing template strings with custom functions before interpolation.

40. What is dynamic import in JavaScript?


Dynamic import (import()) allows loading modules asynchronously when needed.

41. What is the difference between Object.assign() and the spread operator?
Object.assign() copies properties from multiple sources, while the spread operator (...) provides a
more concise syntax for shallow copies.

42. What are promises chaining and promise.all?


Promise chaining allows sequential execution of Promises, while Promise.all() runs multiple
Promises in parallel and resolves when all complete.

43. What is the difference between a shallow copy and a deep copy?
A shallow copy copies object references, while a deep copy recursively clones all nested objects.

44. What is event bubbling and capturing?


Event bubbling propagates events from child to parent, while event capturing moves from parent to
child before bubbling occurs.

45. What is the difference between DOM and virtual DOM?


The DOM represents the web page structure, while the virtual DOM optimizes updates in libraries
like React by reducing direct manipulations.

46. What is tail call recursion, and how does JavaScript optimize it?
Tail call recursion is when a recursive call is the last operation in a function, and JavaScript
optimizes it by reusing stack frames.

47. What are JavaScript iterators and generators?


Iterators define a sequence with next() methods, and generators (function*) produce values lazily
using yield.

48. What is functional programming in JavaScript?


Functional programming emphasizes pure functions, immutability, and higher-order functions to
write cleaner code.

49. How does JavaScript handle memory management?


JavaScript uses garbage collection with reference counting and mark-and-sweep algorithms to free
unused memory.

50. What are ES6+ features that improved JavaScript?


ES6+ introduced let/const, arrow functions, template literals, classes, async/await, spread/rest
operators, and more.

You might also like