React Interview Questions

React is a JavaScript library that helps you build user interfaces for web applications. It's especially popular because of its approach to creating UIs, which focuses on being both declarative and component-based.

Some of the key features of react are as follows:

Component-Based: React lets you break down your user interface into smaller, reusable parts called components. Each component manages its own logic and user interface elements, making it easier to build and maintain complex interfaces.

Declarative: React allows you to describe how your user interface should look based on the current application state. Instead of manually updating the DOM to match the desired UI state, React handles these updates for you.

Virtual DOM: React uses a virtual representation of the DOM to improve performance. Changes to the virtual DOM are compared with the actual DOM, and only the necessary updates are applied, reducing the number of DOM manipulations and improving performance.

JSX: JSX is a syntax extension for JavaScript that lets you write HTML-like code directly in your JavaScript files. This makes it easier to define the structure and behaviour of your React components.

Unidirectional Data Flow: React follows a unidirectional data flow, where data flows from parent to child components. This makes it easier to understand and debug how data changes affect the user interface.

React Hooks: Introduced in React 16.8, hooks are functions that allow you to use state and other React features in functional components. Hooks provides a more flexible way to manage component state and lifecycle methods without using class components.

In summary, React provides a powerful and efficient way to build dynamic and interactive user interfaces for web applications. Its component-based architecture, along with features like the virtual DOM and JSX, make it a popular choice among developers.

Let us look at some of the common interview questions in React:

  1. What is React?
    • React is a JavaScript library for building user interfaces, developed by Facebook.
  2. What are the key features of React?
    • Virtual DOM, JSX, Components, One-way data binding, and Declarative views are key features of React.
  3. What is JSX?
    • JSX is a syntax extension for JavaScript that allows you to write HTML-like code in your React components.
  4. What is the difference between React and React Native?
    • React is a library for building web applications, while React Native is a framework for building native mobile applications using React.
  5. What are the main advantages of using React?
    • Some advantages of using React include its performance optimizations, reusable components, and a strong community.
  6. What is a component in React?
    • A component in React is a reusable piece of UI that can contain its own state and props.
  7. What is the purpose of state in React?
    • State in React is used to store and manage component-specific data that may change over time.
  8. What is the difference between state and props in React?
    • State is internal to a component and can be changed over time, while props are external inputs to a component that are passed in from its parent component and cannot be changed by the component itself.
  9. What is a functional component?
    • A functional component in React is a simple JavaScript function that takes props as an argument and returns JSX.
  10. What is a class component?
    • A class component in React is a JavaScript class that extends the React.Component class and has its own state and lifecycle methods.
  11. What are controlled components in React?
    • Controlled components in React are components whose value is controlled by React and not by the DOM.
  12. What are higher-order components (HOC) in React?
    • Higher-order components (HOC) in React are functions that take a component and return a new component with enhanced functionality.
  13. What is the purpose of keys in React lists?
    • Keys in React lists are used to uniquely identify elements and help React identify which items have changed, been added, or been removed.
  14. What is the context API in React?
    • The context API in React allows you to pass data through the component tree without having to pass props down manually at every level.
  15. What is the purpose of refs in React?
    • Refs in React are used to access the underlying DOM nodes or React elements created in the render method.
  16. What is the difference between createElement and JSX?
    • createElement is a method used to create React elements programmatically, while JSX is a syntax extension for JavaScript that allows you to write HTML-like code in your React components.
  17. What is the useEffect hook in React?
    • The useEffect hook in React is used to perform side effects in function components, such as data fetching, subscriptions, or manually changing the DOM.
  18. What is the useState hook in React?
    • The useState hook in React is used to add state management to functional components.
  19. What is the difference between class components and functional components in React?
    • Class components are ES6 classes that extend React.Component and have their own state and lifecycle methods, while functional components are simple JavaScript functions that take props as an argument and return JSX.
  20. What are the lifecycle methods in React?
    • Lifecycle methods in React are methods that are called at different stages of a component's life, such as componentDidMount, componentDidUpdate, and componentWillUnmount.
  21. What is the purpose of PureComponent in React?
    • PureComponent in React is a class component that implements a shouldComponentUpdate method with a shallow prop and state comparison, which can improve performance by preventing unnecessary re-renders.
  22. What is React Router?
    • React Router is a library for routing in React applications, allowing you to define different routes and render different components based on the current URL.
  23. What is Redux?
    • Redux is a state management library for JavaScript applications, commonly used with React to manage the application's state in a predictable way.
  24. What are the key principles of Redux?
    • The key principles of Redux include maintaining a single source of truth, state is read-only, changes are made with pure functions, and using actions to describe state changes.
  25. What is the purpose of the connect function in React-Redux?
    • The connect function in React-Redux is used to connect a React component to the Redux store, allowing the component to access the store's state and dispatch actions.
  26. What is the useMemo hook in React?
    • The useMemo hook in React is used to memoize a value, preventing expensive calculations from being re-executed on every render.
  27. What is the useCallback hook in React?
    • The useCallback hook in React is used to memoize a callback function, preventing it from being recreated on every render.
  28. What is the useReducer hook in React?
    • The useReducer hook in React is used to manage state in functional components, similar to how reducers are used in Redux.
  29. What is the useContext hook in React?
    • The useContext hook in React is used to consume values from the React context API, allowing components to access context without having to use a consumer component.
  30. What is server-side rendering in React?
    • Server-side rendering in React is the process of rendering React components on the server and sending the pre-rendered HTML to the client, which can improve performance and SEO.

Node Interview Questions

  1. What is Node.js?
    • Node.js is an open-source, server-side JavaScript runtime environment that runs on the V8 engine and allows you to execute JavaScript code outside a web browser.
  2. What is NPM?
    • NPM (Node Package Manager) is a package manager for Node.js that allows developers to easily manage and share reusable code packages.
  3. What is the difference between Node.js and Ajax?
    • Node.js is a server-side runtime environment for JavaScript, while Ajax (Asynchronous JavaScript and XML) is a client-side technique used to send and receive data from a web server asynchronously.
  4. What is an EventEmitter in Node.js?
    • EventEmitter is a class in Node.js that allows you to implement the publish-subscribe pattern for handling events.
  5. What is the purpose of the package.json file in Node.js?
    • The package.json file is used to store metadata about a Node.js project, such as its name, version, dependencies, and scripts.
  6. What is a callback function in Node.js?
    • A callback function is a function that is passed as an argument to another function and is executed after the completion of that function.
  7. What is the difference between synchronous and asynchronous programming in Node.js?
    • Synchronous programming blocks the execution of code until a task is completed, while asynchronous programming allows the code to continue executing while a task is being completed.
  8. What is the purpose of the 'fs' module in Node.js?
    • The 'fs' module is used to perform file system operations, such as reading from and writing to files.
  9. What is middleware in Express.js?
    • Middleware in Express.js are functions that have access to the request and response objects and can modify them or perform additional tasks before passing them on to the next middleware function in the stack.
  10. What is the difference between process.nextTick() and setImmediate() in Node.js?
    • process.nextTick() is used to schedule a callback function to be invoked in the next iteration of the event loop, while setImmediate() is used to schedule a callback function to be invoked in the current iteration of the event loop, after I/O events.
  11. Explain the concept of streams in Node.js.
    • Streams in Node.js are objects that allow you to read or write data sequentially. They are used to process large amounts of data efficiently and can be readable, writable, or duplex (both readable and writable).
  12. What is the purpose of the 'path' module in Node.js?
    • The 'path' module in Node.js provides utilities for working with file and directory paths.
  13. What is the purpose of the 'http' module in Node.js?
    • The 'http' module in Node.js provides functionality for creating HTTP servers and clients.
  14. What is the purpose of the 'crypto' module in Node.js?
    • The 'crypto' module in Node.js provides cryptographic functionality, such as hashing, encryption, and decryption.
  15. How can you handle errors in Node.js?
    • Errors in Node.js can be handled using try-catch blocks for synchronous code and using the error-first callback pattern for asynchronous code.
  16. What is the Event Loop in Node.js?
    • The Event Loop in Node.js is a mechanism that allows Node.js to perform non-blocking I/O operations despite being single-threaded, by offloading operations to the system kernel whenever possible and using callbacks to notify the application when an operation completes.
  17. What is the purpose of the 'os' module in Node.js?
    • The 'os' module in Node.js provides operating system-related utility methods and properties.
  18. What is the purpose of the 'util' module in Node.js?
    • The 'util' module in Node.js provides utility functions that are useful for debugging and error handling.
  19. What is the purpose of the 'child_process' module in Node.js?
    • The 'child_process' module in Node.js allows you to spawn child processes, execute commands in the shell, and communicate with other processes using inter-process communication (IPC).
  20. What is the purpose of the 'cluster' module in Node.js?
    • The 'cluster' module in Node.js allows you to take advantage of multi-core systems by spawning child processes to handle incoming connections, thereby improving the performance of your Node.js applications.
  21. What is the purpose of the 'url' module in Node.js?
    • The 'url' module in Node.js provides utilities for URL resolution and parsing.
  22. What is the purpose of the 'querystring' module in Node.js?
    • The 'querystring' module in Node.js provides utilities for parsing and formatting URL query strings.
  23. How can you handle file uploads in Node.js?
    • File uploads in Node.js can be handled using the 'multer' middleware for Express.js, which allows you to parse multipart/form-data and handle file uploads.
  24. What is the purpose of the 'dotenv' module in Node.js?
    • The 'dotenv' module in Node.js allows you to load environment variables from a .env file into your Node.js application.
  25. What is the purpose of the 'express' module in Node.js?
    • The 'express' module in Node.js is a web application framework that provides a robust set of features for building web applications, including routing, middleware support, and template engines.
  26. How can you handle sessions in Express.js?
    • Sessions in Express.js can be handled using the 'express-session' middleware, which provides session management functionality, such as storing session data in memory or in a database.
  27. What is the purpose of the 'mongoose' module in Node.js?
    • The 'mongoose' module in Node.js is an Object Data Modeling (ODM) library for MongoDB that provides a straightforward way to model your application data and interact with MongoDB.
  28. What is the purpose of the 'jsonwebtoken' module in Node.js?
    • The 'jsonwebtoken' module in Node.js is used to generate and verify JSON Web Tokens (JWTs), which are used for secure authentication and information exchange between parties.
  29. What is the purpose of the 'axios' module in Node.js?
    • The 'axios' module in Node.js is a promise-based HTTP client that allows you to make HTTP requests from your Node.js application.
  30. How can you test Node.js applications?
    • Node.js applications can be tested using testing frameworks such as Mocha, Jest, or Jasmine, along with assertion libraries such as Chai or expect.js. Mocking libraries such as Sinon can also be used to mock dependencies for unit testing.

SQL Interview Questions

  1. What is SQL and why is it important?
    • SQL (Structured Query Language) is a standard language for interacting with databases. It is important because it allows users to access and manipulate data in relational databases.
  2. What are the different types of SQL statements?
    • SQL statements can be broadly classified into four categories:
      • Data Definition Language (DDL) statements: Used to define the database structure (e.g., CREATE, ALTER, DROP).
      • Data Manipulation Language (DML) statements: Used to manipulate data (e.g., SELECT, INSERT, UPDATE, DELETE).
      • Data Control Language (DCL) statements: Used to control access to data (e.g., GRANT, REVOKE).
      • Transaction Control Language (TCL) statements: Used to manage transactions (e.g., COMMIT, ROLLBACK).
  3. What is a primary key?
    • A primary key is a unique identifier for a record in a table. It ensures that each record in the table is uniquely identified and cannot be null.
  4. What is a foreign key?
    • A foreign key is a column or a set of columns in a table that establishes a relationship with the primary key of another table. It is used to ensure referential integrity between the two tables.
  5. What is a join in SQL?
    • A join is used to combine rows from two or more tables based on a related column between them. The most common types of joins are INNER JOIN, LEFT JOIN, RIGHT JOIN, and FULL JOIN.
  6. What is the difference between INNER JOIN and OUTER JOIN?
    • INNER JOIN returns rows when there is at least one match in both tables, while OUTER JOIN returns all rows from one table and the matched rows from the other table (or null if there is no match).
  7. What is the difference between WHERE and HAVING clauses?
    • WHERE clause is used to filter rows before grouping or aggregation, while HAVING clause is used to filter groups after grouping or aggregation.
  8. What is the difference between DELETE and TRUNCATE commands?
    • DELETE command is used to remove rows from a table based on a condition, while TRUNCATE command is used to remove all rows from a table, resetting the table.
  9. What is a subquery?
    • A subquery is a query nested inside another query. It can be used to return data that will be used in the main query as a condition or to retrieve additional data.
  10. What is a view in SQL?
    • A view is a virtual table based on the result of a SELECT query. It allows you to simplify complex queries and restrict access to certain columns or rows of a table.
  11. What is normalization and why is it important?
    • Normalization is the process of organizing data in a database to reduce redundancy and improve data integrity. It involves dividing a database into two or more tables and defining relationships between them.
  12. What is denormalization?
    • Denormalization is the process of adding redundant data to a normalized database to improve read performance. It can help reduce the need for joins and improve query performance.
  13. What is a stored procedure?
    • A stored procedure is a precompiled set of SQL statements that are stored in the database and can be called by name. It is used to encapsulate business logic and improve performance.
  14. What is a trigger in SQL?
    • A trigger is a special type of stored procedure that is automatically executed in response to certain events on a table, such as INSERT, UPDATE, or DELETE operations.
  15. What is the difference between CHAR and VARCHAR data types?
    • CHAR is a fixed-length character data type, while VARCHAR is a variable-length character data type. CHAR pads spaces to the right of the value to fill the fixed length, while VARCHAR does not.
  16. What is the difference between UNION and UNION ALL?
    • UNION combines the results of two or more SELECT statements and removes duplicates, while UNION ALL combines the results of two or more SELECT statements without removing duplicates.
  17. What is ACID in the context of database transactions?
    • ACID stands for Atomicity, Consistency, Isolation, and Durability. It is a set of properties that guarantee that database transactions are processed reliably.
  18. What is a self-join?
    • A self-join is a join that is used to join a table to itself. It is useful when you want to compare rows within the same table.
  19. What is a cursor in SQL?
    • A cursor is a database object that allows you to retrieve rows from a result set one at a time. Cursors are typically used when you need to process individual rows in a result set.
  20. What are the different types of indexes in SQL?
    • The main types of indexes in SQL are clustered indexes, non-clustered indexes, and unique indexes. Clustered indexes determine the physical order of data in a table, while non-clustered indexes do not.
  21. What is the difference between clustered and non-clustered indexes?
    • A clustered index determines the physical order of data in a table and is created on the primary key by default. A non-clustered index does not affect the physical order of data and is created on columns other than the primary key.
  22. What is a constraint in SQL?
    • A constraint is a rule that is enforced on data in a database. It can be used to enforce uniqueness, ensure referential integrity, or restrict the values that can be inserted into a column.
  23. What is the difference between a constraint and a trigger?
    • A constraint is a rule that is enforced on data when it is inserted, updated, or deleted from a table, while a trigger is a stored procedure that is automatically executed in response to certain events on a table.
  24. What is the difference between a SQL statement and a SQL script?
    • A SQL statement is a single SQL command, such as SELECT or INSERT, while a SQL script is a collection of SQL statements that are executed together.
  25. What is the difference between a database and a schema?
    • A database is a collection of tables, indexes, and other objects, while a schema is a container for database objects. A database can have multiple schemas, each containing its own set of objects.
  26. What is the difference between GROUP BY and ORDER BY clauses?
    • GROUP BY clause is used to group rows that have the same values into summary rows, while ORDER BY clause is used to sort the result set by one or more columns.
  27. What is the COALESCE function in SQL?
    • The COALESCE function returns the first non-null value in a list of expressions. It is useful for replacing null values with a default value.
  28. What is the difference between NULL and an empty string?
    • NULL represents a missing or unknown value, while an empty string is a string with zero characters.
  29. What is the difference between the ROLLBACK and COMMIT commands?
    • ROLLBACK command is used to undo transactions that have not been committed, while COMMIT command is used to save transactions to the database.