1. What is React JS?
React JS
React JS is an open-source JavaScript library used to build user interfaces. It was developed by Facebook. It lets us compose complex UIs from small and isolated pieces of code called Components.
2. What are the differences between React JS and JavaScript?
Some of the differences between React JS and JavaScript are:
React JS | JavaScript |
---|---|
React JS is a library based on JavaScript | JavaScript is a scripting language |
Whenever state (data) is changed, it updates only what is necessary by making use of virtual DOM | Whenever data is changed, it updates the whole HTML DOM |
Whenever the state (data) is changed, the component re-renders and React efficiently updates the HTML DOM | If the data is changed, we need to update the HTML DOM by DOM methods/properties |
3. What is React JS used for?
- React is used for building user interfaces specifically for single-page applications.
- React allows us to create reusable components.
- React will efficiently update and render just the right components when the data changes.
4. What are the advantages of React JS?
The following are the major advantages of React JS:
- Easy to Learn
- Large Community
- Developer Toolset
- Open Source
5. How to add a sample React component to an HTML page?
Step 1: In the HTML file, add an HTML
divelement to which we want to add the React implementation.For instance, the
index.htmllooks like this,HTMLStep 2: Add the React Scripts to the same HTML page before the
</body>tag as shown below:HTML
Here, the scripts are added to load/import the React library.
Step 3: Now add one more script, to load our component to the container having id
some_random_idin the above code. Let’s name the JS file asmyComponent.js. Thesrcof the newly added script element should have the path to themyComponent.jsfile as the value.HTMLStep 4: Now, Create and open the file named
myComponent.jsand paste the following code:JSX
Here we have created a React component named
6. Why react is faster than JS?
React is a JavaScript library, thus technically it isn't
7. What are the advantages of React JS over JS?
Compatibility with platforms React JS supports various libraries along with an excellent architecture for app development. The tools can be chosen for customization without any limitations to the platform.
Reusability of components The non-complex logic in the components can be used and maintained easily. Just create a class and make use of as many instances as desired.
Interactive UI To build a user-friendly application with a high success rate, there is a need to have a functional, interactive, and high-quality UI. ReactJS provides declarative components that enable you to develop UI functions and debug them.
Virtual DOM One of ReactJS greatest assets is having a Virtual DOM. React compares new virtual DOM with current virtual DOM, and the difference will be efficiently updated to the Real DOM.
Future-oriented Since ReactJS is compatible with most of the other tools and platforms out there, there is no need to work on the existing code while an update is happening.
Wide Community One primary reason that makes ReactJS ideal for application development is an extensive community of developers always working to better the documentation.
8. What are the advantages of using create-react-app CLI?
Here are few advantages to using
One line command to set up React web app.
No need to mug up all the configuration, because it provides the way to set up and minifies the production-ready app.
Application versioning can be well maintained.
It comes with great package support like ESLint, Babel, Webpack, and so on.
Upgrading the existing app to the latest version is less painful
9. What is the difference between React Native and ReactJS?
ReactJS is a JavaScript library, supporting both front-end web and being run on the server, for building user interfaces and web applications.
React Native is a mobile framework that compiles native app components, allowing you to build native mobile applications (iOS, Android, and Windows) in JavaScript that allows you to use ReactJS to build your components, and implements ReactJS under the hood.
10. What are the differences between React and ReactDom?
React is a JavaScript library for building User Interfaces and ReactDOM is the JavaScript library that allows React to interact with the DOM.
11. Why React instead of Angular?
React uses virtual DOM whereas Angular uses HTML DOM.
React beats Angular in terms of performance as React updates only what is necessary without rewriting the whole HTML DOM.
React has larger community than Angular.
To know more, refer to this link
12. What is the version of React JS you are learning?
- Kindly refer to Introduction to React JS | Cheat Sheet.
13. What is meant by React JSX?
React JS introduced a new HTML like syntax named JSX to create elements.
The above JSX element compiles to,
14. Can web browsers read JSX directly?
Web browsers are capable to read the regular JS objects but not the JSX. Web browsers cannot read JSX directly.
As browsers can read only the regular JS objects, then JSX needs to be converted to the regular JS object by using Babel.
15. What is a React Fragment?
The Fragment is an alternate way to return a single JSX element. It groups a list of children without adding extra nodes to the DOM.
Short Syntax:
16. What is the purpose of render() in React?
The
- It is used to return the JSX that is displayed in the UI.
- It is called whenever the props are updated and state is updated using setStatemethod.
- If more than one HTML element is to be rendered, then they must be grouped using a container element or react fragment.
17. What is the syntax for Conditional Rendering?
Conditional Rendering allows us to render different elements or components based on a condition.
Different ways to implement Conditional Rendering are:
Using an If...Else Statement
Using Element Variables
Using Ternary Operators
Using Logical && Operator