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

JavaScript_React_Interview_Questions-1 (1)

The document provides a compilation of intermediate-level interview questions and answers related to JavaScript and React. Key topics include variable declarations, closures, event loops, promises, error handling, and component types in React. It also covers React-specific concepts such as the Virtual DOM, Hooks, and the importance of unique keys in lists.

Uploaded by

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

JavaScript_React_Interview_Questions-1 (1)

The document provides a compilation of intermediate-level interview questions and answers related to JavaScript and React. Key topics include variable declarations, closures, event loops, promises, error handling, and component types in React. It also covers React-specific concepts such as the Virtual DOM, Hooks, and the importance of unique keys in lists.

Uploaded by

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

JavaScript and React Intermediate-Level Interview Questions with Answers

Q: What is the difference between `var`, `let`, and `const` in JavaScript?

A: var: Function-scoped and can be redeclared. let: Block-scoped and cannot be redeclared. const:

Block-scoped, cannot be redeclared, and must be initialized.

Q: Explain closures in JavaScript with an example.

A: A closure is a function that retains access to its parent scope even after the parent function has

closed. Example:

function outer() {

let count = 0;

return function inner() {

return ++count;

};

const counter = outer();

counter(); // 1

Q: How does the JavaScript event loop work?

A: The event loop continuously checks the call stack and the task queue. If the call stack is empty, it

pushes tasks from the queue to the stack for execution.

Q: What are promises in JavaScript? How do they differ from async/await?

A: Promises are objects representing eventual completion or failure of an async operation.

async/await provides syntactic sugar to work with promises, making code more readable.

Q: What is hoisting in JavaScript? Which variables or functions are hoisted?

A: Hoisting is JavaScript's behavior of moving declarations to the top of the scope. var and function

declarations are hoisted, but let and const are not initialized.
Q: What are higher-order functions in JavaScript? Can you give an example?

A: Higher-order functions take other functions as arguments or return functions. Example:

Array.map, filter.

Q: What is the difference between `==` and `===`? Which one should be used and why?

A: `==` performs type coercion before comparison. `===` checks both value and type. `===` is

recommended for strict equality.

Q: Explain the difference between call, apply, and bind methods in JavaScript.

A: call: Invokes a function with a specific this and arguments. apply: Similar to call but takes

arguments as an array. bind: Returns a new function with specified this.

Q: What are JavaScript prototypes? How is inheritance implemented using prototypes?

A: Prototypes are objects from which other objects inherit properties. Inheritance is implemented by

setting an object's prototype to another object.

Q: What are the different types of errors in JavaScript? How would you handle them?

A: Types: SyntaxError, TypeError, ReferenceError, etc. Use try-catch blocks or the onerror event for

handling errors.

Q: What is the difference between functional components and class components in React?

A: Functional components are stateless and simpler, while class components can manage state and

lifecycle methods.

Q: What is the Virtual DOM in React, and how does it help in performance optimization?

A: The Virtual DOM is a lightweight copy of the real DOM. React uses it to minimize real DOM

manipulations, improving performance.

Q: What are React Hooks? Explain the `useState` and `useEffect` hooks with examples.

A: Hooks enable functional components to use state and lifecycle features. Example: useState
manages state, useEffect handles side effects.

Q: How would you handle forms in React? Explain with an example of controlled vs.

uncontrolled components.

A: Controlled components use state to manage input values. Uncontrolled components use refs to

directly access DOM values.

Q: What is the purpose of `key` props in lists? Why are unique keys important in React?

A: Keys help React identify which items changed, improving rendering performance. Unique keys

prevent bugs during re-rendering.

You might also like