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

Javascript

This document contains 50 JavaScript interview questions covering various topics such as language fundamentals, asynchronous programming, DOM manipulation, and error handling. Key concepts include closures, promises, event delegation, and differences between synchronous and asynchronous code. It serves as a comprehensive guide for preparing for JavaScript interviews.
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)
2 views

Javascript

This document contains 50 JavaScript interview questions covering various topics such as language fundamentals, asynchronous programming, DOM manipulation, and error handling. Key concepts include closures, promises, event delegation, and differences between synchronous and asynchronous code. It serves as a comprehensive guide for preparing for JavaScript interviews.
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/ 12

50 JavaScript

Interview
Questions
by Rupendra Ragala
Basics & Fundamentals
1.What is JavaScript and how is it different
from Java?
JavaScript is a scripting language mainly used
for dynamic content in web browsers. Java is a
programming language for general-purpose
applications. JavaScript runs in the browser,
Java runs in JVM.
2. Explain let, const, and var.
var: Function scoped, can be hoisted.
let: Block scoped, not hoisted.
const: Block scoped, cannot be reassigned.
3. What is a closure in JavaScript?
A closure is a function that remembers its
outer variables even after the outer function
has returned.
4.What is hoisting?
JavaScript's behavior of moving declarations
to the top. Variables declared with var and
functions are hoisted.
5. Difference between == and ===?
a.==: Compares value (type coercion
allowed).
b.===: Compares value and type (strict
equality).
6. What is the event loop?
The mechanism that handles asynchronous
operations by pushing callbacks into a queue
once the call stack is empty.
7. What are promises?
Promises represent the eventual result of an
asynchronous operation. States: pending,
fulfilled, rejected.
8. What is async/await?
Syntax sugar over promises to write
asynchronous code in a synchronous style.
9. What is the use of this keyword?
Refers to the current execution context. Its
value depends on how a function is called.
10. What is a callback function?
A function passed as an argument to another
function to be executed later.
11. How to select elements in DOM?
document.getElementById('id')
document.querySelector('.class')
document.querySelectorAll('div')
12. What is event delegation?
Handling events at a parent level using
bubbling, reducing the number of event
listeners.

13. What is bubbling and capturing in JS


events?
Bubbling: Event goes from target to top.
Capturing: Event goes from top to target.
14. How do you prevent default behavior in an
event?
Use event.preventDefault();.
15. Difference between innerText,
textContent, and innerHTML?
innerText: Visible text only.
textContent: All text.
innerHTML: Includes HTML tags.
16. What are arrow functions?
Shorter syntax for functions. Do not bind this.
17. Difference between regular function and
arrow function?
Arrow functions do not have their own this,
cannot be used as constructors, and do not
have arguments.
18. What is function currying?
Transforming a function with multiple
arguments into a series of functions each
taking one argument.
19. What is a pure function?
A function that does not change external state
and returns the same output for the same
input.
20. What are higher-order functions?
Functions that take other func
tions as arguments or return functions.
21. How to clone an object in JavaScript?
Object.assign({}, obj)
{...obj}
JSON.parse(JSON.stringify(obj)) (deep
copy)
22. What are array methods you frequently
use?
map(), filter(), reduce(), forEach(), find(),
includes().
23. Difference between map() and forEach()?
map() returns a new array.
forEach() executes callback without
returning.

24. How do you find duplicates in an array?


Use a Set or frequency counter.
25. How do you merge two arrays?
[...arr1, ...arr2]
arr1.concat(arr2)
26. What is the difference between
synchronous and asynchronous code?
Synchronous code blocks execution.
Asynchronous code runs in the background
without blocking.
27. What are common APIs used for async
operations?
fetch(), setTimeout(), setInterval(), Promises,
async/await.
28. How to handle error in async/await?
Wrap in try...catch.
29. What is the use of Promise.all()?
Runs multiple promises in parallel and waits for
all to complete.
30. What is a race condition in JavaScript?
When the timing of asynchronous operations
causes unpredictable behavior.
31. What is destructuring in JS?
Extracting values from arrays/objects into
variables:
Ex: const {name} = user;
32. What are template literals?
Js sample: `Hello ${name}`
33. What is spread operator?
Expands elements:
Js example : [...arr], {...obj}
34. What is rest parameter?
Aggregates args into an array:
Js example: function fn(...args) {}
35. What is a symbol in JS?
Unique and immutable primitive value, often
used as object keys.
36. How do you handle exceptions?
Js example: try { ... } catch (error) { ... }
37. What are common JS errors?
ReferenceError
TypeError
SyntaxError
38. How do you debug JavaScript code?
Use console.log(), browser DevTools,
breakpoints.
39. What is the finally block used for?
Executes code after try and catch regardless
of outcome.

40. How do you throw a custom error?


Js example:
throw new Error("Something went wrong");
41. What is debouncing and throttling?
Debounce: Delay a function call until no
more calls are made.
Throttle: Limit a function call to once per
interval.
42. How do you secure JavaScript code?
Avoid eval
Use HTTPS
Avoid exposing sensitive info in JS
43. How do you handle browser compatibility
issues?
Use polyfills
Use Babel for transpilation
44. How do you write modular JavaScript code?
Use ES6 modules (import, export), or module
bundlers like Webpack.
45. What tools do you use for testing JS code?
Jest, Mocha, Chai, Cypress.
46. What is garbage collection in JS?
Automatic memory management that removes
objects no longer in use.
47. What is a memory leak?
When memory is not released due to lingering
references.
48. What is the difference between null and
undefined?
undefined: Variable declared but not
assigned.
null: Explicitly assigned to represent no
value.
49. Explain the concept of immutability.
Once created, the value cannot be changed.
Used in Redux, functional programming.
50. How does JavaScript handle concurrency?
Single-threaded via event loop and non-blocking
I/O using callback queue and microtask queue.
Hope this is
helpful, like and
share it with your
friends
By Rupendra Ragala

You might also like