50 Most Common ReactJS Interview Questions from Basic to Advanced
50 Most Common ReactJS Interview Questions from Basic to Advanced Picture 1
ReactJS is one of the popular libraries in the IT industry and it is the most popular front-end technology. If you are preparing for an interview about ReactJS, here are 50 most common ReactJS interview questions that TipsMake has collected.
1. What is ReactJS?
ReactJS is an open source JavaScript library developed by Facebook in 2013, aimed at building user interfaces (UI) for web applications. This library allows programmers to create independent and reusable UI components, increasing the flexibility and scalability of the application.
2. Explain MVC architecture
The components of the MVC model include model, view, controller. Each component will play a separate role.
Model: The Model represents the data and business logic of the application. It is where the current state of the data is stored and managed, providing methods to access and update that data. When there is a change in the data, the Model notifies the View to update the user interface.
View: View is the user interface part, responsible for displaying data from the Model visually. View does not interact directly with the Model but only receives data from the Controller to display to the user. Interface components such as buttons, charts and tables all belong to View.
Controller: The Controller acts as a bridge between the Model and the View. It handles requests from the user, updates the Model when necessary, and notifies the View to update the interface accordingly. When the user performs an action (such as clicking or entering data), the Controller recognizes that action and performs the necessary operations.
3. Explain the basic components of React
Components
Components are the basic units in React that help structure user interfaces. Each component can contain separate HTML, CSS, and JavaScript code, allowing for reuse and easy management. There are two main types of components:
● Class Components: Defined using classes and can contain lifecycle methods.
● Function Components: Defined using functions, are usually simpler and more readable.
JSX (JavaScript XML)
JSX is a JavaScript syntax extension that makes it easy to write HTML in JavaScript. It helps combine HTML code with JavaScript logic, making interface development more intuitive.
Props (Properties)
Props are a way to pass data from a parent component to a child component. They are immutable, meaning that once set, the value of the props cannot be changed in the child component. Props help components interact with each other and create dynamic interfaces.
State
State represents the internal state of a component. When the state changes, React automatically updates the UI to reflect the change. State can be changed through events or user actions, creating an interactive experience.
Virtual DOM
Virtual DOM is a virtual copy of the actual DOM. React uses Virtual DOM to optimize performance by comparing the difference between the Virtual DOM and the actual DOM before making an update. This reduces the number of updates required to the actual DOM, improving the speed and performance of the application.
4. Explain props and state in React with the difference
Props and state are two important concepts that help manage data in components. Props are properties passed from parent components to child components. They are like parameters of a function, allowing communication between components. Props are immutable, their value cannot be changed.
State is an object that stores a component's internal data. Unlike props, state can change throughout the component's lifecycle. When state changes, React automatically re-renders the component to reflect the new changes.
Difference between props and state in React:
5. What is virtual DOM in React?
The Virtual DOM in React is a JavaScript representation of the actual DOM structure. When the state of the application changes, React creates a new Virtual DOM to reflect these changes, thereby minimizing the number of direct updates to the actual DOM, thereby improving the speed and performance of the application.
6. What is JSX?
JSX, short for JavaScript XML, is a syntax extension for the JavaScript language that allows programmers to write HTML code in JavaScript easily. JSX was developed by Facebook primarily for use with the React library, helping to create user interfaces in an intuitive and efficient way.
7. What is a component and what are the types of components in React?
Components in React are a fundamental building block of an application, allowing developers to break down the user interface (UI) into separate, independent, and reusable pieces. Each component can receive data via properties (props) and return React elements (usually JSX) to be displayed in the browser.
In React, there are two main types of components:
- Function Components: Are JavaScript functions that take props and return a React element. They have no state and do not use lifecycle methods.
- Class Components: Are JavaScript classes that can store state and use lifecycle methods.
8. How does the browser read JSX?
When you write JSX code, it is converted into JavaScript function calls by a compiler like Babel. For example, the following JSX code:
const element =
Hello, world!
;
will be compiled to:
const element = React.createElement('h1', null, 'Hello, world!')
9. Explain the steps to create a React application and print Hello World?
To create a simple React application and print out "Hello World", you can follow the steps below:
Step 1: Install Node.js and npm
First, you need to install Node.js and npm (the package manager for Node.js). You can download Node.js from the official page at nodejs.org. When you install Node.js, npm will be installed automatically along with it.
Step 2: Install Create React App
After installing Node.js and npm, open Terminal or Command Prompt and run the following command to install Create React App:
npm install -g create-react-app
This command will install Create React App on your computer, allowing you to create React apps easily.
Step 3: Create a new React project
Next, you can create a new React project by running the following command in Terminal or Command Prompt:
npx create-react-app my-app
Replace "my-app" with whatever name you want for your project. Once the command completes, you will have a new directory containing the standard React project structure.
Step 4: Run the application
Go into the newly created project directory and start the application using the following commands:
cd my-app
npm start
This command will open your default browser and run the application at: http://localhost:3000.
Step 5: Edit the App.js file to display "Hello World"
Open the src/App.js file in your source code editor. Change the contents of this file as follows to display "Hello World":
import React from 'react';
function App() {
return (
Hello, World!
);
}
export default App;
Save the file. The browser will automatically reload and display "Hello, World!" on the web page.
10. How to create events in React?
To create an event in React, you first need to define a function that will handle the event. This function will contain the logic that you want to execute when the event occurs. For example, if you want to display a message when the user clicks a button, you might define the function like this:
function handleClick() {
alert("You clicked on me!");
Once you've defined the function, you need to add it to the JSX element you want to assign the event to. In this case, you'll add an onClick attribute to the tag.
11. Explain creating List in React?
The most common way to create a list in React is to use the array's map() method. This method allows you to iterate over the elements in the array and convert them into JSX elements.
12. What is a lock in React?
Keys are special attributes used to uniquely identify elements in an array of components. They help React determine which elements have changed, been added, or been removed when there is a change in the application's state or data.
13. How to write comments in React?
● To write a single-line comment in JSX, you can use the following syntax:
{/* This is a one line comment */}
● If you want to write a multi-line comment, you use the same syntax but extend it across multiple lines:
{/*
This is the comment
multi-line
*/}
14. Explain the difference between React and Angular?
Below is a comparison table between React and Angular, which will help you easily see the difference between the two technologies:
15. Explain how to use render method in React?
Rendering is the process that React uses to display content on the user interface (UI) based on changes to properties (props) and state (state).
To trigger the first render, you will use the createRoot method from the react-dom/client library, then call the render method with the component.
When a component is rendered, React performs the following steps:
● Call component: React will call the component's render function to get the output.
● Compare to Virtual DOM: React compares the new output to the Virtual DOM to determine what changes are needed.
● Update the real DOM: Finally, React will update the real DOM based on the calculated changes.
16. What is state in React?
In React, state is an important concept used to manage and track data that changes over time in an application. State is used to represent information that can change, such as user input, API results, or any data that needs to be updated and displayed on the user interface.
17. Explain about props in React?
Props are component input parameters in React. They allow you to pass data and configuration to child components, similar to attributes in HTML. An important point is that props are immutable, meaning once passed to a component, they cannot be modified by that component.
18. What are high-level components in React?
Higher-Order Components (HOCs) in React are an important concept for reusing logic between components. They are JavaScript functions that take a component and return a new component, allowing you to add additional functionality without changing the structure of the original component.
19. Explain the difference between functional components and class components in React?
In React, there are two main types of components: Function Components and Class Components. Each has its own characteristics and is used in different situations.
Class Components
● Syntax: Written in ES6 class syntax and requires inheritance from React.Component.
● State management: Ability to manage state through this.state and lifecycle methods like componentDidMount, componentDidUpdate, and componentWillUnmount.
● Render method: Must use render() method to return JSX element.
● Use case: Often used when complex state management is required or when lifecycle methods are required. They are suitable for components with a lot of processing logic.
Function Components
● Syntax: Is a normal JavaScript function, does not require inheritance from any class.
● State management: Initially there was no state management capability, but from React version 16.8 onwards, it is possible to use Hooks (like useState and useEffect) to manage state and external effects.
● Return JSX: Return JSX directly from within the function without the need for a render method.
● Use case: Suitable for simple components that do not require complex state management. They help write concise and readable code
20. Explain one-way data binding in React?
Data binding is the process of connecting components in an application. In React, one-way data binding means that data is only passed from parent component to child component via props. This means:
● Data flows in one direction: Data is managed and circulated from the parent component to the child component. The child component cannot directly change the parent component's data, but can only send information back through events such as button clicks or data input.
● Data change event: When data needs to be changed, the child component will trigger an action (event), and the parent component will handle the data update. This process helps maintain consistency and easily control the data flow in the application.
21. What is conditional rendering in React?
Conditional rendering in React allows you to render different components based on the state of your application. Similar to JavaScript, you can use the if statement, the ternary operator, or the logical operator && to decide whether a component should be rendered or not.
22. What is React Router?
React Router is an important library in React application development, allowing to manage navigation between pages and components without having to reload the entire page.
23. Explain the components of react-router
The main components of React Router include:
● BrowserRouter: Is an application wrapper component that uses the HTML5 History API to synchronize URLs with application state.
● Route: Defines a specific path and connects it to a component. When the URL matches this path, the corresponding component will be rendered.
● Link: Create a link to a specific path within the app, allowing navigation between pages without reloading.
● Switch: Selects a single Route from multiple possible Routes that match the current path, ensuring only one component is displayed at a time.
24. Explain the life cycle methods of components
The product life cycle describes the development and existence of a product from its introduction until its withdrawal from the market. The PLC is often divided into four main stages:
● Development and introduction: This is the first stage where the product is developed from idea to market launch. During this stage, the business needs to invest in research and development, as well as build an initial marketing strategy.
● Growth: After launch, if the product is successful, sales will grow rapidly. Businesses need to optimize marketing campaigns to attract customers and expand the market.
● Maturity: This stage occurs when sales peak and begin to stabilize. Businesses need to stay competitive through product innovation or price adjustments.
● Decline: Eventually, sales begin to decline due to a variety of factors such as substitution by new products or changes in consumer demand. The business must make a decision about whether to continue with the product or withdraw from the market.
25. Explain the methods used in the assembly phase of components
Each component in React has a clear lifecycle, consisting of three main phases: Mounting, Updating, and Unmounting. Lifecycle methods are called during each of these phases, allowing the developer to intervene in the process of initializing and updating the component.
Mounting Phase
During this phase, the component is attached to the DOM. There are four main methods called in order:
● constructor(): This is the first method called when a component is instantiated. Here you can set the initial state and bind methods if needed.
● static getDerivedStateFromProps(): This method is called right after the constructor and before rendering. It allows you to update the state based on changes in props.
● render(): This method is required and will always be called to return the JSX that the component will render.
● componentDidMount(): This method is called after the component has been rendered for the first time and mounted to the DOM, often used to perform tasks such as calling an API or setting up a subscription
Updating Phase
When a component's state or props change, React updates the component. The lifecycle methods in this phase include:
● static getDerivedStateFromProps(): Similar to the mounting phase, but called before each re-render.
● shouldComponentUpdate(): This method allows you to control whether the component should re-render or not. If false is returned, the rendering process will be skipped.
● render(): Called to update the user interface with new data.
● getSnapshotBeforeUpdate(): Allows you to get information from the DOM before a change occurs.
● componentDidUpdate(): Called immediately after the component has updated and re-rendered.
Unmounting Phase
When a component is no longer needed and is removed from the DOM, the method:
● componentWillUnmount(): Called to perform cleanup tasks like canceling a subscription or timer
26. What is the this.setState function in React?
The this.setState function in React is an important method used to update the state of a component. The this.setState function allows you to change the value of the state in a component. When you call this function, React will automatically update the new state and trigger a re-render of the component to show the latest data.
27. What is the function of ref in React?
Refs (references) are an object used to hold a reference to a variable or component, allowing its value to remain unchanged between renders. They provide direct access to DOM nodes or React elements created in the render method.
28. What is Hook in React?
React Hooks are a set of functions that let you 'hook into' React's state and lifecycle features from functional components. React Hooks simplify state management and component lifecycle interactions, making code more readable and maintainable.
29. Explain useState hook in React?
useState is one of the most fundamental hooks in React, introduced in version 16.8. It allows you to manage state in Functional Components, which was previously only possible in Class Components. This hook simplifies state management and improves the interactivity of your application.
30. Explain useEffect hook in React?
useEffect is a hook in React that is used to manage side effects in Functional Components. Side effects include tasks like calling APIs, changing the DOM, or interacting with external libraries. This hook helps you perform tasks that are not part of rendering the user interface and gives you control over when these tasks are performed.
31. What are React Fragments?
React Fragments is a feature introduced in React 16 that allows you to group multiple children without creating redundant DOM nodes, improving performance and making the code cleaner.
32. What are React Developer Tools?
React Developer Tools is a browser extension that makes it easy for developers to inspect and debug React applications. It provides an overview of the component tree structure, as well as the current state and props of each component in the application.
33. How to use styles in ReactJS?
To use styles in ReactJS, you can apply the following four main methods:
Inline Styling
Inline styling allows you to apply styles directly to elements via the style attribute. Styles are defined as JavaScript objects, with properties using camelCase syntax instead of hyphenated as in regular CSS.
CSS Stylesheet
Using CSS Stylesheets is the traditional way to style your application. You create a separate CSS file and import it into your component.
How to do:
● Create CSS file (eg: App.css):
body {
background-color: #008080;
color: yellow;
padding: 40px;
font-family: Arial;
text-align: center;
}
● Import into component: import './App.css';
This method is useful when styles do not need to change with state.
CSS Modules
CSS Modules allow you to define styles for each component separately, avoiding class name conflicts. This makes managing styles easier and keeps each component unique.
Styled Components
Styled-components is a library that allows you to write styles at the component level, using ES6 syntax like this npm install styled-components --save. This approach is very flexible and makes it easy to create custom styled components.
34. Explain styled components in React?
In React, components are the basic building blocks of user interfaces. They allow developers to break down the interface into independent, reusable, and easy-to-manage pieces. Here's an explanation of the main components in React.
35. What is Prop Drilling?
Prop Drilling (also known as "threading") is a situation where data is passed from a parent component through multiple levels of child components until it reaches the component that needs to use that data. This process can become complex and difficult to manage as an application grows, resulting in code that becomes harder to read and maintain.
36. What is Custom Hook in React?
A Custom Hook is a JavaScript function whose name starts with "use" (according to React naming conventions), which allows you to use other hooks inside it. The main goal of a Custom Hook is to share logic between multiple components without having to pass props through multiple levels.
37. How to optimize React code?
To optimize React code, there are some important techniques that programmers should apply:
● Use React.memo: React.memo helps prevent unnecessary re-rendering for components that don't change their props. By wrapping your components in React.memo, you can improve your app's performance.
● Optimize rendering with useMemo and useCallback: Use useMemo to memorise expensive computations and useCallback to preserve the callback function between renders. This reduces the need to re-create the function and reduces the number of renders for child components.
● Lazy Loading and Code Splitting: Lazy loading allows parts of the application to be loaded as needed, while code splitting breaks the code into smaller bundles, reducing initial page load time.
● Use Transitions: With React 18, you can use startTransition to differentiate between urgent and non-urgent updates, which helps React handle them better.
38. What is the difference between useref and createRef in React?
The difference between useRef and createRef in React mainly lies in how they work and the context in which they are used:
Context of use
● useRef: Is a hook used in functional components and keeps the value between renders.
● createRef: Used mainly in class components and creates a new ref every time the component is rendered.
Behavior between renders
● useRef: Keep the same ref object across renders, allowing you to store values without causing a re-render of the component.
● createRef: Creates a new ref every time the component renders, thus not retaining the value between renders.
How to initialize
● useRef(initialValue): Can take an initial value and will return the same ref object throughout the component's lifetime.
● createRef(): Does not accept an initial value; the current value will be set to null initially.
39. What is React-redux?
React-Redux is a library that bridges React and Redux, helping to manage state in React applications efficiently. React-Redux provides APIs to easily integrate Redux into React applications, allowing components to access global state stored in the Redux store without having to pass props through multiple component levels.
40. What are the benefits of using react-redux?
Benefits of using React-Redux in app development:
● Complex state management: Redux helps manage complex states efficiently, allowing components to access and update from a single source, minimizing props passing.
● State prediction: The "state is read-only" principle and reducers ensure easy state prediction, supporting operations like undo and redo.
● Easy debugging: Redux provides action and state history tracking, helping programmers identify the cause of errors. Redux DevTools supports time-based debugging.
● Consistency: The "single source of truth" principle maintains data consistency through action dispatching by the reducer, minimizing errors.
● Optimized performance: Redux only updates necessary components when state changes, improving performance, especially in large applications.
● Extensibility: Redux supports middleware integration to extend functionality, allowing for asynchronous processing, logging, and data formatting, improving customization and extensibility.
41. Explain the core components of react-redux?
Store
The Store is where the entire application state is stored. It represents the only state tree in Redux.
The function of the store is:
● Stores the current state of the application.
● Provides methods like getState() to get the state, dispatch(action) to dispatch actions, and subscribe(listener) to register to listen for state changes.
State
State is an object that contains all the application's data, managed in a single place in the store. State in Redux is immutable, meaning you cannot change it directly but must go through actions.
Actions
Actions are JavaScript objects that represent events or state changes. Each action needs a type property to specify the type of action.
An action can be defined as follows:
Actions help define how the state will change when an event occurs.
Reducers
Reducers are pure functions that take the current state and an action and return a new state. They specify how the state should change based on the action received. Reducers do not change the original state but return a new state based on the current state and the action.
Provider
Provider is a component from the react-redux library that connects the Redux store to the entire React application. When you use Provider, you wrap the application with it so that every component can access the store.
Selectors
Selectors are functions that select a piece of state from the store and pass it to a component. They help optimize data access and management in Redux.
42. How can we combine multiple reducers in React?
To combine multiple reducers in React, you can use two main methods: Redux and React Hooks with useReducer and useContext. Here are two ways you can combine multiple reducers in React:
Using Redux
Redux allows you to combine multiple reducers into one large reducer using the combineReducers function. This helps manage more complex state in your application. Here's how to do it:
● Install Redux: First, you need to install Redux and react-redux.
● Create Reducers: Define individual reducers for each part of the application state.
const counterReducer = (state = { count: 0 }, action) => {
switch(action.type) {
case 'INCREMENT':
return { .state, count: state.count + 1 };
case 'DECREMENT':
return { .state, count: state.count - 1 };
default:
return state;
}
};
const userReducer = (state = { name: '' }, action) => {
// Logic for userReducer
};
● Combine Reducers: Use combineReducers to combine reducers.
import { combineReducers } from 'redux';
const rootReducer = combineReducers({
counter: counterReducer,
user: userReducer,
});
● Create Store: Create a store with the associated rootReducer.
import { createStore } from 'redux';
const store = createStore(rootReducer);
Using React Hooks with useReducer and useContext
If you don't want to use Redux, you can combine useReducer and useContext to manage state in React:
- Create Context: First, create a context to share state between components.
import React, { createContext, useReducer } from 'react';
const StateContext = createContext();
- Define Reducer: Create a reducer to handle actions.
const initialState = { count: 0 };
const reducer = (state, action) => {
switch(action.type) {
case 'INCREMENT':
return { .state, count: state.count + 1 };
case 'DECREMENT':
return { .state, count: state.count - 1 };
default:
return state;
}
};
● Provide Context: Use a provider to provide state to child components.
const StateProvider = ({ children }) => {
const [state, dispatch] = useReducer(reducer, initialState);
return (
{children}
);
};
● Using Context in Components: Child components can use context to access state and dispatch actions.
import React, { useContext } from 'react';
const CounterComponent = () => {
const { state, dispatch } = useContext(StateContext);
return (
Count: {state.count}
);
};
43. What is Context API?
The Context API is a built-in feature in React that allows sharing data between components without having to pass props through each level (also known as "prop drilling"), simplifying the management of global state in the application and improving code reusability.
44. Explain about provider and consumer in ContextAPI?
Provider
Provider is a React component that is used to provide values to child components in the component tree. It takes a value prop, which contains the data you want to share.
Usage: When you create a context object using React.createContext(), you can use Provider to wrap components that need access to that value.
Consumer
Consumer is a component that allows you to access the value provided by Provider. It uses a render prop to get the value from the context.
Usage: You can use Consumer to get value from context as follows:
const ChildComponent = () => (
{theme => Our theme is: {theme}}
In this example, ChildComponent will display "Our theme is: dark" if it is in the subtree of ThemeContext.Provider.
45. Explain CORS in React?
CORS, or Cross-Origin Resource Sharing, is a security mechanism in web browsers that allows or blocks requests from a different origin than the one the application is running on. This is a common problem when developing React applications, especially when the frontend and backend are deployed on different domains.
46. What is Axios and how to use it in React?
Axios is a popular HTTP client library in JavaScript, built on the Promise object. It allows developers to easily send asynchronous HTTP requests to REST APIs, supporting flexible CRUD (Create, Read, Update, Delete) operations in frontend applications such as React, Angular and Vue.js.
To use Axios in a React app, you need to follow these steps:
● Step 1: Install Axios
Open terminal and run the following command to install Axios:
or if you use Yarn:
● Step 2: Use Axios to call the API
Here's an example of how to use Axios to make a GET request in a React component:
import React, { useEffect, useState } from 'react';
import axios from 'axios';
function App() {
const [data, setData] = useState([]);
useEffect(() => {
const fetchData = async () => {
try {
const response = await axios.get('https://jsonplaceholder.typicode.com/users');
setData(response.data);
} catch (error) {
console.error("Error fetching data:", error);
}
};
fetchData();
}, []);
return (
List of Users
{data.map(user => (
- {user.name}
))}
);
}
export default App;
In there:
● useEffect: This hook is used to call the API right after the component is mounted. In this case, it will call the fetchData function to get data from the API.
● axios.get(): This method is used to send a GET request to the API. The response data will be saved to the state via setData.
● Error Handling: Use try-catch to handle errors when calling the API.
● Step 3: Make a POST request
To send data to the API, you can use the POST method as follows:
const postData = async(newUser) => {
try {
const response = await axios.post('https://jsonplaceholder.typicode.com/users', newUser);
setData(prevData => [.prevData, response.data]);
} catch (error) {
console.error("Error posting data:", error);
}
};
In the above code, newUser is the object that contains the data you want to send to the API.
Using Axios in React simplifies communication with web services and makes data management more efficient.
47. What is React-Material UI?
Material-UI, now known as MUI, is an open-source library of React components based on Google's Material Design. It makes it easy for developers to build beautiful and consistent user interfaces for web applications.
48. What is Flux architecture in Redux?
Flux architecture is a state management pattern developed by Facebook, primarily to support building applications with React. It is not a library or framework, but a way to organize source code in a unidirectional data flow, making it easy to manage and track the application state.
49. Explaining concurrent rendering in React
Concurrent Rendering is an important feature introduced in React 18, which aims to improve performance and user experience in React applications. This feature allows React to perform multiple user interface (UI) updates at the same time without slowing down the main thread of the application.
50. How to create a simple counter using React
To create a simple counter in React, you can use the useState hook to manage the state of the counter. Here is a detailed tutorial with sample source code.
Step 1: Create Counter component
First, you need to create a Counter component to display and control the counter. The code below illustrates how to do this:
import React, { useState } from 'react';
const Counter = () => {
const [count, setCount] = useState(0); // Initialize state for counter
return (
{count}
{/* Display counter value */}
{/* Increment button */}
{/* Decrease button */}
{/* Reset button */}
);
};
export default Counter;
Step 2: Use the Counter component in the main application
Once you have created the Counter component, you need to use it in your main application. Here is the source code for the main application:
import React from 'react';
import ReactDOM from 'react-dom';
import Counter from './Counter'; // Import the Counter component
const App = () => {
return (
Simple Counter
{/* Using the Counter component */}
);
};
ReactDOM.render(, document.getElementById('root'));
In there:
● useState: The useState hook is used to create a state variable count, initialized with a value of 0. The setCount function is used to update the value of count.
● Control buttons: Each button has an onClick event handler to increment, decrement, or reset the counter value.
● Display value: The current value of the counter is displayed in the H1 tag.
Hopefully, through this article, you have gained more useful information about ReactJS interview questions. Mastering knowledge from basic to advanced will help you not only pass the interview round but also develop your programming skills.
You should read it
- Questions to interview IT people need to understand
- 15 questions to interview for an extremely 'bad brain' job
- What is ReactJS? What can ReactJS be used for?
- 49 most asked questions that Apple asked in the job interview
- The secret to answering the 15 most frequently asked interview questions
- 15 questions interview the 'hottest' programmers and answer suggestions
- 200 common Java interview questions, with reference answers
- Smart answers when asked in an interview: Do you want to ask any questions?
- What do employers want to know about you when asking this question in an interview?
- What is ReactJS? Why ReactJS is the future of web development
- 18 'extremely difficult' recruitment questions from Apple
- Ask yourself these 10 questions before the interview to gain more confidence