0% found this document useful (0 votes)
1K views9 pages

20 Most Asked Javascrpt Questions

The document provides a comprehensive overview of 20 commonly asked JavaScript questions along with their answers. Topics covered include JavaScript fundamentals, variable declarations, functions, promises, event handling, and modern features like modules and destructuring. It serves as a useful resource for individuals looking to test or enhance their JavaScript knowledge.
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)
1K views9 pages

20 Most Asked Javascrpt Questions

The document provides a comprehensive overview of 20 commonly asked JavaScript questions along with their answers. Topics covered include JavaScript fundamentals, variable declarations, functions, promises, event handling, and modern features like modules and destructuring. It serves as a useful resource for individuals looking to test or enhance their JavaScript knowledge.
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/ 9

Hamza Ullah

Full Stack Engineer

20 most asked
JavaScript questions
and its answsers!
See how many you know
already!
1. What is JavaScript?
Hamza Ullah
Answer: Full Stack Engineer
JavaScript is a high-level, interpreted scripting language primarily used for creating
dynamic content on web pages. It enables interactivity on websites and is commonly
used in both client-side and server-side development.

2. What are the differences between var, let, and const in JavaScript?
Answer:
var is function-scoped or globally scoped and allows redeclaration.
let is block-scoped and does not allow redeclaration within the same scope.
const is block-scoped, but its value cannot be reassigned after initialization.

3. Explain the concept of closures in JavaScript.


Answer:
A closure is a function that retains access to its lexical scope even after the function
that created it has finished execution. This allows inner functions to reference
variables from the outer function even after the outer function has returned.
4. What is the difference between null and undefined?
Hamza Ullah
Answer: Full Stack Engineer
null is an explicit assignment of a "no value" or empty object reference.
undefined is a variable that has been declared but has not yet been assigned a
value.

5. What is a JavaScript promise?


Answer:
A JavaScript promise is an object that represents the eventual completion (or failure)
of an asynchronous operation. It allows for chaining asynchronous operations and
handling errors.

6. What is event delegation in JavaScript?


Answer:
Event delegation is a technique where you attach a single event listener to a parent
element rather than multiple event listeners to child elements. This improves
performance, especially when dealing with dynamic elements added to the DOM.
7. Explain the this keyword in JavaScript. Hamza Ullah
Full Stack Engineer
Answer:
The this keyword refers to the context in which the function is called. It can point to
different objects depending on how the function is invoked:
In a method, this refers to the object the method is called on.
In a regular function, this refers to the global object (or undefined in strict mode).
In an arrow function, this lexically binds to the value of this in the enclosing
scope.

8. What are JavaScript hoisting and its effects?


Answer:
Hoisting is JavaScript's behavior of moving variable and function declarations to the
top of their containing scope during compilation. However, only the declarations are
hoisted, not the initializations. For variables declared with let and const, they are
hoisted but remain in a "temporal dead zone" until assigned.

9. What is a JavaScript callback function?


Answer:
A callback function is a function passed as an argument to another function, which is
then invoked at a later time when a certain condition or operation is completed.
Hamza Ullah
Full Stack Engineer
10. What is the difference between == and === in JavaScript?
Answer:
== is the equality operator that compares two values for equality after converting
them to a common type (type coercion).
=== is the strict equality operator that compares both the value and the type
without type coercion.

11. What are JavaScript events and event handling?


Answer:
Events are actions that occur in the browser (such as a click or keypress) that
JavaScript can listen for and respond to. Event handling refers to the process of
attaching event listeners to DOM elements to perform actions when events occur.
Hamza Ullah
12. What is the difference between apply(), call(), and bind()? Full Stack Engineer
Answer:
apply() and call() are used to invoke a function with a specified this value and
arguments.
call() takes arguments directly.
apply() takes arguments as an array.
bind() returns a new function with a specified this value and optionally fixed
arguments, but it doesn't invoke the function immediately.

13. Explain the concept of promises chaining in JavaScript.


Answer:
Promise chaining allows you to link multiple asynchronous operations. After a
promise is resolved, you can chain .then() methods to handle the next operations in
sequence. Each .then() returns a new promise, enabling further chaining.
14. What is the difference between forEach() and map() in JavaScript? Hamza Ullah
Answer: Full Stack Engineer
forEach() executes a provided function once for each array element, but it does
not return anything (undefined).
map() also iterates over each element but returns a new array with the results of
the callback function applied to each element.

15. What are JavaScript modules?


Answer:
JavaScript modules are reusable pieces of code that can be imported and exported
from one file to another. ES6 introduced import and export to allow modularization
of code, making it more maintainable and scalable.

16. What is the use of the setTimeout() and setInterval() functions?


Answer:
setTimeout() is used to execute a function after a specified delay (once).
setInterval() is used to execute a function repeatedly at a specified interval.
Hamza Ullah
Full Stack Engineer
17. What are arrow functions and how do they differ from regular functions?
Answer:
Arrow functions are a concise way to write functions. They have a different behavior
for the this keyword compared to regular functions because they lexically bind this to
the enclosing scope.

18. What is a JavaScript generator function?


Answer:
A generator function is a special type of function that can yield multiple values over
time, pausing execution at each yield statement. It allows asynchronous-like
behavior, using the yield keyword and next() method to manage execution flow.
Hamza Ullah
Full Stack Engineer
19. What is the purpose of the bind() method in JavaScript?
Answer:
The bind() method is used to create a new function that, when invoked, has its this
value set to the provided value. It can also pass arguments to the function that
remain fixed when the function is called.

20. What is destructuring in JavaScript?


Answer:
Destructuring is a convenient way to extract values from arrays or objects and assign
them to variables in a single statement. It makes the code more readable and concise.

const [a, b] = [1, 2]; // Array destructuring


const {name, age} = {name: 'Alice', age: 25}; // Object destructuring

You might also like