Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
2 views

JavaScript Interview Question

The document contains a list of common interview questions and answers related to JavaScript, covering topics such as data types, variable declarations, functions, asynchronous programming, and error handling. Key concepts like closures, promises, event delegation, and the DOM are also explained. It serves as a comprehensive guide for understanding essential JavaScript principles and practices.

Uploaded by

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

JavaScript Interview Question

The document contains a list of common interview questions and answers related to JavaScript, covering topics such as data types, variable declarations, functions, asynchronous programming, and error handling. Key concepts like closures, promises, event delegation, and the DOM are also explained. It serves as a comprehensive guide for understanding essential JavaScript principles and practices.

Uploaded by

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

Interview Questions of JavaScript

1. What is JavaScript?

Answer: JavaScript is a programming language used primarily to create interactive and dynamic
content on websites. It can be used for both client-side and server-side development.

2. What are the data types in JavaScript?

Answer: JavaScript supports the following data types:

• Primitive: String, Number, Boolean, Undefined, Null, Symbol, BigInt


• Non-primitive: Object (including Array, Function, etc.)
3. Explain the difference between let, const, and var.

Answer:

• var is function-scoped and can be re-declared.


• let is block-scoped and can't be re-declared but can be updated.
• const is block-scoped, can't be re-declared, and can't be updated (must be initialized).
4. What is Hoisting in JavaScript?

Answer: Hoisting is JavaScript's default behavior of moving declarations to the top of the current
scope before code execution. It applies to both variables and functions.

5. Explain Arrow Functions and their bene ts.

Answer: Arrow functions provide a shorter syntax for writing functions and do not have their own
this context, which helps avoid issues with scope in callbacks.

javascript
Copy code
const sum = (a, b) => a + b;
6. What is the difference between == and === in JavaScript?

Answer:

• == checks for value equality and performs type conversion.


• === checks for both value and type equality without type conversion.
7. What is a Closure in JavaScript?

Answer: A closure is a feature in JavaScript where an inner function has access to its own scope,
the outer function’s scope, and the global scope. It helps in data encapsulation and maintaining
state.

8. What are Promises in JavaScript?

Answer: Promises are used to handle asynchronous operations in JavaScript. A promise represents
a value which may be available now, in the future, or never.
fi
9. What is an IIFE (Immediately Invoked Function Expression)?

Answer: An IIFE is a function that runs immediately after it is de ned. It's useful for creating a new
scope to avoid variable pollution.

javascript
Copy code
(function() {
console.log("IIFE executed");
})();
10. Explain the concept of this keyword in JavaScript.

Answer: The this keyword refers to the object that is executing the current function. Its value
depends on how the function is called.

11. What is the Event Loop in JavaScript?

Answer: The event loop is responsible for handling asynchronous callbacks in JavaScript. It
continuously checks the call stack and the callback queue to process events and execute code.

12. Explain async and await in JavaScript.

Answer: async and await are used for handling promises more ef ciently. async makes a
function return a promise, and await makes the code wait for the promise to resolve.

13. What is the difference between null and undefined?

Answer:

• null is an assignment value that represents no value or an empty value.


• undefined means a variable has been declared but has not yet been assigned a value.
14. Explain the concept of Prototypal Inheritance.

Answer: Prototypal inheritance in JavaScript is a way to add properties and methods to an object.
Objects inherit directly from other objects through prototypes.

15. What is the use of call(), apply(), and bind() methods?

Answer:

• call() and apply() are used to invoke a function with a speci c this value.
• bind() creates a new function with a xed this value.
16. Explain Event Delegation.

Answer: Event delegation is a technique to handle events ef ciently by attaching a single event
listener to a parent element to manage all child elements, using the event's bubbling phase.
fi
fi
fi
fi
fi
17. What are JavaScript Arrays and how do you manipulate them?

Answer: Arrays in JavaScript are used to store multiple values in a single variable. Methods like
push(), pop(), shift(), unshift(), map(), filter(), and reduce() are used
to manipulate arrays.

18. What is the spread operator?

Answer: The spread operator (...) allows an iterable to be expanded in places where multiple
elements or arguments are expected.

javascript
Copy code
let arr = [1, 2, 3];
console.log(...arr); // 1 2 3
19. What is Destructuring in JavaScript?

Answer: Destructuring is a syntax that allows extracting values from arrays or properties from
objects into distinct variables.

javascript
Copy code
let [a, b] = [1, 2];
let {x, y} = {x: 10, y: 20};
20. What is JSON and how is it used?

Answer: JSON (JavaScript Object Notation) is a lightweight data interchange format. It is used to
store and transport data, often in API calls.

21. What is the DOM (Document Object Model)?

Answer: The DOM is a programming interface for HTML and XML documents, representing the
page's structure as a tree of objects that can be manipulated with JavaScript.

22. How do you create and trigger events in JavaScript?

Answer: Events can be created using methods like addEventListener() and triggered
using dispatchEvent().

23. What are setTimeout() and setInterval() functions?

Answer:

• setTimeout() is used to execute a function after a speci ed delay.


• setInterval() is used to execute a function repeatedly with a xed time delay
between each call.
fi
fi
24. Explain the concept of Asynchronous JavaScript.

Answer: Asynchronous JavaScript allows code to execute without blocking the main thread.
Techniques like callbacks, promises, and async/await are used for handling asynchronous
operations.

25. What is a Callback Function?

Answer: A callback function is a function passed as an argument to another function, which is


executed after the completion of that function.

26. What are Higher-Order Functions?

Answer: Higher-order functions are functions that take other functions as arguments or return them
as results.

27. What is Type Coercion in JavaScript?

Answer: Type coercion refers to the automatic or implicit conversion of values from one data type
to another (like converting strings to numbers).

28. Explain the concept of try, catch, and finally.

Answer: These blocks are used for error handling:

• try executes the code.


• catch handles any errors.
• finally executes code regardless of the result.
29. What is Strict Mode in JavaScript?

Answer: Strict mode is a way to opt into a restricted variant of JavaScript, catching common
coding bugs and preventing unsafe actions.

30. Explain how fetch() works in JavaScript.

Answer: The fetch() method is used to make network requests to APIs and returns a promise
that resolves to the response object.

You might also like