{"id":54,"date":"2026-07-02T16:27:25","date_gmt":"2026-07-02T10:57:25","guid":{"rendered":"https:\/\/smitabharat.com\/blog\/?p=54"},"modified":"2026-08-01T23:43:08","modified_gmt":"2026-08-01T18:13:08","slug":"react-questions","status":"publish","type":"post","link":"https:\/\/smitabharat.com\/blog\/react-questions\/","title":{"rendered":"React Questions"},"content":{"rendered":"<h1>1.What is JSX in React?<\/h1>\n<p><strong>JSX<\/strong> stands for <strong>JavaScript XML<\/strong>.<\/p>\n<p>It is a <strong>syntax extension<\/strong> for JavaScript used in <strong>React<\/strong> to write <strong>HTML-like code inside JavaScript<\/strong>.<\/p>\n<p><strong>Why Use JSX?<\/strong><\/p>\n<p>JSX makes it <strong>easier to build UI<\/strong> in React by letting you write components using syntax that looks like HTML, but is actually <strong>converted to JavaScript<\/strong> behind the scenes.<\/p>\n<h1>2.What is component in react<\/h1>\n<p>In <strong>React<\/strong>, a <strong>component<\/strong> is a <strong>reusable, self-contained piece of UI<\/strong> \u2014 like a function or class \u2014 that returns <strong>JSX<\/strong> (HTML-like syntax) to describe <strong>what should appear on the screen<\/strong>.<\/p>\n<p><strong>\ud83e\udde0 Simple Definition<\/strong><\/p>\n<p>A <strong>component<\/strong> is a <strong>function or class<\/strong> that returns <strong>React elements<\/strong> (usually written in JSX) to be rendered on the web page.<\/p>\n<table>\n<thead>\n<tr>\n<td><strong>Feature<\/strong><\/td>\n<td><strong>Purpose<\/strong><\/td>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>props<\/td>\n<td>Input data passed from parent<\/td>\n<\/tr>\n<tr>\n<td>state (in hooks)<\/td>\n<td>Internal data that changes over time<\/td>\n<\/tr>\n<tr>\n<td>useEffect<\/td>\n<td>Lifecycle behavior (e.g., fetch API)<\/td>\n<\/tr>\n<tr>\n<td>event handlers<\/td>\n<td>Handle user interactions<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>&nbsp;<\/p>\n<h2>3. what is props state hook in react<\/h2>\n<p><strong>Props are inputs<\/strong> to a component.<\/p>\n<p>\uf0b7\u00a0 Used to <strong>pass data from parent to child<\/strong> component.<\/p>\n<p>\uf0b7\u00a0 <strong>Read-only<\/strong> \u2013 the child component <strong>cannot modify<\/strong> props.<\/p>\n<p><strong>2\ufe0f<\/strong><strong>\u20e3 State<\/strong><\/p>\n<p><strong>\ud83d\udca1 What it is:<\/strong><\/p>\n<ul>\n<li><strong>State is local data<\/strong> that a component <strong>manages itself<\/strong>.<\/li>\n<li>State can <strong>change over time<\/strong>, usually in response to user actions.<\/li>\n<li>State changes cause the component to <strong>re-render<\/strong>.<\/li>\n<\/ul>\n<p>import { useState } from &#8216;react&#8217;;<\/p>\n<p>&nbsp;<\/p>\n<p>function Counter() {<\/p>\n<p>const [count, setCount] = useState(0);<\/p>\n<p>&nbsp;<\/p>\n<p>return (<\/p>\n<p>&lt;&gt;<\/p>\n<p>&lt;p&gt;Count: {count}&lt;\/p&gt;<\/p>\n<p>&lt;button onClick={() =&gt; setCount(count + 1)}&gt;Increment&lt;\/button&gt;<\/p>\n<p>&lt;\/&gt;<\/p>\n<p>);<\/p>\n<p>}<\/p>\n<p>&nbsp;<\/p>\n<p><strong>Hooks<\/strong><\/p>\n<p><strong>\ud83d\udca1 What it is:<\/strong><\/p>\n<ul>\n<li><strong>Hooks are functions<\/strong> that let you \u201chook into\u201d React\u2019s features (state, lifecycle, etc.) <strong>in functional components<\/strong>.<\/li>\n<li>Hooks are used <strong>only inside functional components<\/strong> (not class components).<\/li>\n<\/ul>\n<ul>\n<li><strong>Common React Hooks:<\/strong><\/li>\n<\/ul>\n<table>\n<thead>\n<tr>\n<td><strong>Hook<\/strong><\/td>\n<td><strong>Purpose<\/strong><\/td>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>useState()<\/td>\n<td>Add state to a functional component<\/td>\n<\/tr>\n<tr>\n<td>useEffect()<\/td>\n<td>Run side effects (like API calls)<\/td>\n<\/tr>\n<tr>\n<td>useContext()<\/td>\n<td>Use global context values<\/td>\n<\/tr>\n<tr>\n<td>useRef()<\/td>\n<td>Get reference to DOM or a value<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>&nbsp;<\/p>\n<h2>4.\u00a0Diff between angular and react<\/h2>\n<ul>\n<li>Angular: A full-fledged framework (developed by Google). It comes with routing, state management, form handling, HTTP client, etc. \u2192 batteries included.<\/li>\n<li>React: A UI library (developed by Meta\/Facebook). Focuses only on building UI components. For routing, state management, etc., you add third-party libraries (e.g., React Router, Redux).<\/li>\n<\/ul>\n<p>\ud83d\udd39 2. Language<\/p>\n<ul>\n<li>Angular: Uses TypeScript by default (strictly typed).<\/li>\n<li>React: Uses JavaScript (with optional TypeScript).<\/li>\n<\/ul>\n<p>\ud83d\udd39 3. Learning Curve<\/p>\n<ul>\n<li>Angular: Steeper \u2192 you need to learn concepts like modules, decorators, dependency injection, RxJS (observables).<\/li>\n<li>React: Easier to pick up \u2192 learn JSX, props, state, hooks. More flexible but requires picking additional libraries for big projects.<\/li>\n<\/ul>\n<p>\ud83d\udd39 4. Performance<\/p>\n<ul>\n<li>Angular: Uses a real DOM (with change detection) but optimized with zone.js and ahead-of-time (AOT) compilation.<\/li>\n<li>React: Uses a Virtual DOM that efficiently updates only the changed parts \u2192 often faster for frequent UI updates.<\/li>\n<\/ul>\n<p>\ud83d\udd39 5. Architecture<\/p>\n<ul>\n<li>Angular: Opinionated, MVC\/MVVM-style architecture. Code is more structured.<\/li>\n<li>React: Flexible, unopinionated. You can structure your app however you want.<\/li>\n<\/ul>\n<p>\ud83d\udd39 6. Ecosystem<\/p>\n<ul>\n<li>Angular: Provides almost everything out of the box (routing, forms, HTTP, testing).<\/li>\n<li>React: Huge ecosystem, but you need to choose packages for routing, state management, forms, etc.<\/li>\n<\/ul>\n<p>\ud83d\udd39 7. Use Cases<\/p>\n<ul>\n<li>Angular: Good for large-scale enterprise apps (e.g., dashboards, CRMs, ERPs) where strict structure helps big teams.<\/li>\n<li>React: Good for dynamic, fast UIs (e.g., single-page apps, social media, e-commerce) where flexibility is needed.<\/li>\n<\/ul>\n<h2><strong>5.what is == and === in react?<\/strong><\/h2>\n<p class=\"PDq2pG_selectionAnchorContainer\" data-start=\"0\" data-end=\"126\">In React, <code data-start=\"10\" data-end=\"14\">==<\/code> and <code data-start=\"19\" data-end=\"24\">===<\/code> are <strong data-start=\"29\" data-end=\"53\">JavaScript operators<\/strong>. React itself doesn&#8217;t define them\u2014it simply uses JavaScript expressions.<\/p>\n<p data-start=\"128\" data-end=\"156\">The important difference is:<\/p>\n<div class=\"TyagGW_tableContainer\">\n<div class=\"group TyagGW_tableWrapper flex flex-col-reverse w-fit\" tabindex=\"-1\">\n<table class=\"w-fit min-w-(--thread-content-width)\" data-start=\"158\" data-end=\"347\">\n<thead data-start=\"158\" data-end=\"206\">\n<tr data-start=\"158\" data-end=\"206\">\n<th class=\"last:pe-10\" data-start=\"158\" data-end=\"169\" data-col-size=\"sm\">Operator<\/th>\n<th class=\"last:pe-10\" data-start=\"169\" data-end=\"176\" data-col-size=\"sm\">Name<\/th>\n<th class=\"last:pe-10\" data-start=\"176\" data-end=\"187\" data-col-size=\"sm\">Compares<\/th>\n<th class=\"last:pe-10\" data-start=\"187\" data-end=\"206\" data-col-size=\"sm\">Type Conversion<\/th>\n<\/tr>\n<\/thead>\n<tbody data-start=\"256\" data-end=\"347\">\n<tr data-start=\"256\" data-end=\"297\">\n<td data-start=\"256\" data-end=\"263\" data-col-size=\"sm\"><code data-start=\"258\" data-end=\"262\">==<\/code><\/td>\n<td data-start=\"263\" data-end=\"280\" data-col-size=\"sm\">Loose Equality<\/td>\n<td data-start=\"280\" data-end=\"288\" data-col-size=\"sm\">Value<\/td>\n<td data-start=\"288\" data-end=\"297\" data-col-size=\"sm\">\u2705 Yes<\/td>\n<\/tr>\n<tr data-start=\"298\" data-end=\"347\">\n<td data-start=\"298\" data-end=\"306\" data-col-size=\"sm\"><code data-start=\"300\" data-end=\"305\">===<\/code><\/td>\n<td data-start=\"306\" data-end=\"324\" data-col-size=\"sm\">Strict Equality<\/td>\n<td data-start=\"324\" data-end=\"339\" data-col-size=\"sm\">Value + Type<\/td>\n<td data-start=\"339\" data-end=\"347\" data-col-size=\"sm\">\u274c No<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<ul>\n<li data-section-id=\"18r945o\" data-start=\"2899\" data-end=\"2972\"><code data-start=\"2901\" data-end=\"2905\">==<\/code> (loose equality) compares values after performing type conversion.<\/li>\n<li data-section-id=\"16o17y0\" data-start=\"2973\" data-end=\"3057\"><code data-start=\"2975\" data-end=\"2980\">===<\/code> (strict equality) compares both value and data type without type conversion.<\/li>\n<li data-section-id=\"1lvjxzr\" data-start=\"3058\" data-end=\"3210\" data-is-last-node=\"\">In React and modern JavaScript, <code data-start=\"3092\" data-end=\"3097\">===<\/code> is recommended because it prevents bugs caused by implicit type coercion and makes comparisons more predictable.<\/li>\n<\/ul>\n<h2>6.what is diff betn var, let, constant in react?<\/h2>\n<h2 class=\"PDq2pG_selectionAnchorContainer\" data-section-id=\"j2qile\" data-start=\"171\" data-end=\"190\">Comparison Table<\/h2>\n<div class=\"TyagGW_tableContainer\">\n<div class=\"group TyagGW_tableWrapper flex flex-col-reverse w-fit\" tabindex=\"-1\">\n<table class=\"w-fit min-w-(--thread-content-width)\" data-start=\"192\" data-end=\"557\">\n<thead data-start=\"192\" data-end=\"229\">\n<tr data-start=\"192\" data-end=\"229\">\n<th class=\"last:pe-10\" data-start=\"192\" data-end=\"202\" data-col-size=\"sm\">Feature<\/th>\n<th class=\"last:pe-10\" data-start=\"202\" data-end=\"210\" data-col-size=\"sm\"><code data-start=\"204\" data-end=\"209\">var<\/code><\/th>\n<th class=\"last:pe-10\" data-start=\"210\" data-end=\"218\" data-col-size=\"sm\"><code data-start=\"212\" data-end=\"217\">let<\/code><\/th>\n<th class=\"last:pe-10\" data-start=\"218\" data-end=\"229\" data-col-size=\"sm\"><code data-start=\"220\" data-end=\"227\">const<\/code><\/th>\n<\/tr>\n<\/thead>\n<tbody data-start=\"268\" data-end=\"557\">\n<tr data-start=\"268\" data-end=\"304\">\n<td data-start=\"268\" data-end=\"276\" data-col-size=\"sm\">Scope<\/td>\n<td data-start=\"276\" data-end=\"287\" data-col-size=\"sm\">Function<\/td>\n<td data-start=\"287\" data-end=\"295\" data-col-size=\"sm\">Block<\/td>\n<td data-start=\"295\" data-end=\"304\" data-col-size=\"sm\">Block<\/td>\n<\/tr>\n<tr data-start=\"305\" data-end=\"348\">\n<td data-start=\"305\" data-end=\"325\" data-col-size=\"sm\">Can be redeclared<\/td>\n<td data-start=\"325\" data-end=\"333\" data-col-size=\"sm\">\u2705 Yes<\/td>\n<td data-start=\"333\" data-end=\"340\" data-col-size=\"sm\">\u274c No<\/td>\n<td data-start=\"340\" data-end=\"348\" data-col-size=\"sm\">\u274c No<\/td>\n<\/tr>\n<tr data-start=\"349\" data-end=\"393\">\n<td data-start=\"349\" data-end=\"369\" data-col-size=\"sm\">Can be reassigned<\/td>\n<td data-start=\"369\" data-end=\"377\" data-col-size=\"sm\">\u2705 Yes<\/td>\n<td data-start=\"377\" data-end=\"385\" data-col-size=\"sm\">\u2705 Yes<\/td>\n<td data-start=\"385\" data-end=\"393\" data-col-size=\"sm\">\u274c No<\/td>\n<\/tr>\n<tr data-start=\"394\" data-end=\"500\">\n<td data-start=\"394\" data-end=\"404\" data-col-size=\"sm\">Hoisted<\/td>\n<td data-start=\"404\" data-end=\"441\" data-col-size=\"sm\">\u2705 Yes (initialized as <code data-start=\"428\" data-end=\"439\">undefined<\/code>)<\/td>\n<td data-start=\"441\" data-end=\"470\" data-col-size=\"sm\">\u2705 Yes (Temporal Dead Zone)<\/td>\n<td data-start=\"470\" data-end=\"500\" data-col-size=\"sm\">\u2705 Yes (Temporal Dead Zone)<\/td>\n<\/tr>\n<tr data-start=\"501\" data-end=\"557\">\n<td data-start=\"501\" data-end=\"522\" data-col-size=\"sm\">Preferred in React<\/td>\n<td data-start=\"522\" data-end=\"529\" data-col-size=\"sm\">\u274c No<\/td>\n<td data-start=\"529\" data-end=\"537\" data-col-size=\"sm\">\u2705 Yes<\/td>\n<td data-start=\"537\" data-end=\"557\" data-col-size=\"sm\">\u2705 Most Preferred<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<ul>\n<li data-section-id=\"1kk74m\" data-start=\"4080\" data-end=\"4206\"><code data-start=\"4082\" data-end=\"4087\">var<\/code> is <strong data-start=\"4091\" data-end=\"4110\">function-scoped<\/strong>, can be <strong data-start=\"4119\" data-end=\"4133\">redeclared<\/strong> and <strong data-start=\"4138\" data-end=\"4152\">reassigned<\/strong>, and is hoisted with an initial value of <code data-start=\"4194\" data-end=\"4205\">undefined<\/code>.<\/li>\n<li data-section-id=\"1jyxg98\" data-start=\"4207\" data-end=\"4374\"><code data-start=\"4209\" data-end=\"4214\">let<\/code> is <strong data-start=\"4218\" data-end=\"4234\">block-scoped<\/strong>, cannot be redeclared in the same scope, but <strong data-start=\"4280\" data-end=\"4301\">can be reassigned<\/strong>. It is hoisted but remains in the <strong data-start=\"4336\" data-end=\"4358\">Temporal Dead Zone<\/strong> until declared.<\/li>\n<li data-section-id=\"1pjujic\" data-start=\"4375\" data-end=\"4595\"><code data-start=\"4377\" data-end=\"4384\">const<\/code> is also <strong data-start=\"4393\" data-end=\"4409\">block-scoped<\/strong>, cannot be redeclared or reassigned, and must be initialized when declared. While a <code data-start=\"4494\" data-end=\"4501\">const<\/code> object&#8217;s properties can be modified, the variable itself cannot reference a different object.<\/li>\n<li data-section-id=\"zp36da\" data-start=\"4596\" data-end=\"4727\" data-is-last-node=\"\">In React, <strong data-start=\"4608\" data-end=\"4643\"><code data-start=\"4610\" data-end=\"4617\">const<\/code> is the preferred choice<\/strong>, <code data-start=\"4645\" data-end=\"4650\">let<\/code> is used only when reassignment is necessary, and <code data-start=\"4700\" data-end=\"4705\">var<\/code> is generally avoided.<\/li>\n<\/ul>\n<h3 class=\"PDq2pG_selectionAnchorContainer\" data-section-id=\"151j70r\" data-start=\"3626\" data-end=\"3658\">Which should you use in React?<\/h3>\n<ul data-start=\"3660\" data-end=\"3975\">\n<li data-section-id=\"1n5okc6\" data-start=\"3660\" data-end=\"3795\"><strong data-start=\"3662\" data-end=\"3673\"><code data-start=\"3664\" data-end=\"3671\">const<\/code><\/strong> \u2192 Default choice. Use it for variables, functions, imports, objects, arrays, and components that don&#8217;t need reassignment.<\/li>\n<li data-section-id=\"l2rvyf\" data-start=\"3796\" data-end=\"3860\"><strong data-start=\"3798\" data-end=\"3807\"><code data-start=\"3800\" data-end=\"3805\">let<\/code><\/strong> \u2192 Use only when the variable needs to be reassigned.<\/li>\n<li data-section-id=\"1epmf2w\" data-start=\"3861\" data-end=\"3975\"><strong data-start=\"3863\" data-end=\"3872\"><code data-start=\"3865\" data-end=\"3870\">var<\/code><\/strong> \u2192 Avoid in modern React development because its function scope and hoisting behavior can lead to bugs.<\/li>\n<\/ul>\n<h2>7. what is virtual DOM?<\/h2>\n<p>Virtual DOM is a lightweight, in-memory JavaScript representation of the real DOM. React updates the Virtual DOM first, compares it with the previous Virtual DOM using a diffing algorithm, and then updates only the changed parts of the real DOM. This makes UI updates faster and more efficient.<\/p>\n<h3 class=\"PDq2pG_selectionAnchorContainer\" data-section-id=\"140vbd7\" data-start=\"394\" data-end=\"423\">Why do we need Virtual DOM?<\/h3>\n<p data-start=\"425\" data-end=\"497\">Updating the <strong data-start=\"438\" data-end=\"450\">Real DOM<\/strong> is expensive because every change may trigger:<\/p>\n<ul data-start=\"499\" data-end=\"555\">\n<li data-section-id=\"yxksn1\" data-start=\"499\" data-end=\"511\">Repainting<\/li>\n<li data-section-id=\"1qh9m3s\" data-start=\"512\" data-end=\"543\">Reflow (layout recalculation)<\/li>\n<li data-section-id=\"pczkn6\" data-start=\"544\" data-end=\"555\">Rendering<\/li>\n<\/ul>\n<p data-start=\"557\" data-end=\"623\">For large applications, frequent DOM updates can slow down the UI.<\/p>\n<p data-start=\"625\" data-end=\"672\">React solves this by using the <strong data-start=\"656\" data-end=\"671\">Virtual DOM<\/strong>.<\/p>\n<hr data-start=\"674\" data-end=\"677\" \/>\n<h3 data-section-id=\"1delv7c\" data-start=\"679\" data-end=\"704\">Real DOM vs Virtual DOM<\/h3>\n<div class=\"TyagGW_tableContainer\">\n<div class=\"group TyagGW_tableWrapper flex flex-col-reverse w-fit\" tabindex=\"-1\">\n<table class=\"w-fit min-w-(--thread-content-width)\" data-start=\"706\" data-end=\"1065\">\n<thead data-start=\"706\" data-end=\"732\">\n<tr data-start=\"706\" data-end=\"732\">\n<th class=\"last:pe-10\" data-start=\"706\" data-end=\"717\" data-col-size=\"sm\">Real DOM<\/th>\n<th class=\"last:pe-10\" data-start=\"717\" data-end=\"732\" data-col-size=\"md\">Virtual DOM<\/th>\n<\/tr>\n<\/thead>\n<tbody data-start=\"760\" data-end=\"1065\">\n<tr data-start=\"760\" data-end=\"845\">\n<td data-start=\"760\" data-end=\"798\" data-col-size=\"sm\">Actual HTML elements in the browser<\/td>\n<td data-start=\"798\" data-end=\"845\" data-col-size=\"md\">JavaScript object representation of the DOM<\/td>\n<\/tr>\n<tr data-start=\"846\" data-end=\"881\">\n<td data-start=\"846\" data-end=\"863\" data-col-size=\"sm\">Slow to update<\/td>\n<td data-start=\"863\" data-end=\"881\" data-col-size=\"md\">Fast to update<\/td>\n<\/tr>\n<tr data-start=\"882\" data-end=\"949\">\n<td data-start=\"882\" data-end=\"916\" data-col-size=\"sm\">Updates the entire affected DOM<\/td>\n<td data-start=\"916\" data-end=\"949\" data-col-size=\"md\">Updates only changed elements<\/td>\n<\/tr>\n<tr data-start=\"950\" data-end=\"1029\">\n<td data-start=\"950\" data-end=\"989\" data-col-size=\"sm\">Browser performs layout calculations<\/td>\n<td data-start=\"989\" data-end=\"1029\" data-col-size=\"md\">React performs comparisons in memory<\/td>\n<\/tr>\n<tr data-start=\"1030\" data-end=\"1065\">\n<td data-start=\"1030\" data-end=\"1047\" data-col-size=\"sm\">More expensive<\/td>\n<td data-start=\"1047\" data-end=\"1065\" data-col-size=\"md\">Less expensive<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<hr data-start=\"1067\" data-end=\"1070\" \/>\n<h3 data-section-id=\"1dofkcj\" data-start=\"1072\" data-end=\"1095\">How Virtual DOM Works<\/h3>\n<p data-start=\"1097\" data-end=\"1116\">Suppose your UI is:<\/p>\n<div class=\"relative w-full mt-4 mb-1\">\n<div class=\"\">\n<div class=\"contents\">\n<div class=\"border border-token-border-light border-radius-3xl corner-superellipse\/1.1 rounded-3xl\">\n<div class=\"relative h-full w-full border-radius-3xl bg-(--code-block-surface) corner-superellipse\/1.1 overflow-clip rounded-3xl [--code-block-surface:var(--bg-elevated-secondary)] dark:[--code-block-surface:var(--composer-surface-primary)] lxnfua_clipPathFallback\">\n<div class=\"pointer-events-none absolute inset-x-4 top-12 bottom-4\">\n<div class=\"pointer-events-none sticky z-40 shrink-0 z-1!\">\n<div class=\"sticky bg-token-border-light\"><code><span class=\"\u037co\">&lt;h1&gt;<\/span>Hello<span class=\"\u037co\">&lt;\/h1&gt;<\/span><\/code><\/div>\n<\/div>\n<\/div>\n<div class=\"relative\">\n<div class=\"\">\n<div class=\"\">React creates a Virtual DOM object:<\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<div class=\"relative w-full mt-4 mb-1\">\n<div class=\"\">\n<div class=\"contents\">\n<div class=\"border border-token-border-light border-radius-3xl corner-superellipse\/1.1 rounded-3xl\">\n<div class=\"relative h-full w-full border-radius-3xl bg-(--code-block-surface) corner-superellipse\/1.1 overflow-clip rounded-3xl [--code-block-surface:var(--bg-elevated-secondary)] dark:[--code-block-surface:var(--composer-surface-primary)] lxnfua_clipPathFallback\">\n<div class=\"pointer-events-none absolute inset-x-4 top-12 bottom-4\">\n<div class=\"pointer-events-none sticky z-40 shrink-0 z-1!\">\n<div class=\"sticky bg-token-border-light\"><code>{<\/code><\/div>\n<\/div>\n<\/div>\n<div class=\"relative\">\n<div class=\"h-full min-h-0 min-w-0\">\n<div class=\"h-full min-h-0 min-w-0\">\n<div class=\"\">\n<div class=\"relative\">\n<div class=\"\">\n<div class=\"relative z-0 flex max-w-full\">\n<div id=\"code-block-viewer\" class=\"q9tKkq_viewer cm-editor z-10 light:cm-light dark:cm-light flex h-full w-full flex-col items-stretch \u037cd \u037cr\" dir=\"ltr\">\n<div class=\"cm-scroller\">\n<pre class=\"cm-content q9tKkq_readonly m-0\"><code>  <span class=\"\u037co\">type<\/span>: <span class=\"\u037ck\">\"h1\"<\/span>,\r\n  <span class=\"\u037cm\">props<\/span>: {\r\n    <span class=\"\u037co\">children<\/span>: <span class=\"\u037ck\">\"Hello\"<\/span>\r\n  }\r\n}\r\n\r\n<\/code><\/pre>\n<h3 class=\"PDq2pG_selectionAnchorContainer\" data-section-id=\"1ytbd1s\" data-start=\"3263\" data-end=\"3290\">Advantages of Virtual DOM<\/h3>\n<pre class=\"cm-content q9tKkq_readonly m-0\"><code><\/code><\/pre>\n<ul data-start=\"3292\" data-end=\"3478\">\n<li data-section-id=\"tk1wkh\" data-start=\"3292\" data-end=\"3311\">Faster UI updates<\/li>\n<li data-section-id=\"1cgxku8\" data-start=\"3312\" data-end=\"3332\">Better performance<\/li>\n<li data-section-id=\"16a2k99\" data-start=\"3333\" data-end=\"3372\">Reduces unnecessary DOM manipulations<\/li>\n<li data-section-id=\"1ldip3v\" data-start=\"3373\" data-end=\"3394\">Efficient rendering<\/li>\n<li data-section-id=\"1dz6rbn\" data-start=\"3395\" data-end=\"3432\">Provides a smoother user experience<\/li>\n<li data-section-id=\"17rqe9u\" data-start=\"3433\" data-end=\"3478\">Simplifies building complex user interfaces<\/li>\n<\/ul>\n<h2>8. what is advantages of typescript?<\/h2>\n<p>TypeScript is a <strong data-start=\"16\" data-end=\"42\">superset of JavaScript<\/strong> developed by Microsoft. It adds <strong data-start=\"75\" data-end=\"92\">static typing<\/strong>, interfaces, generics, and other features to make JavaScript applications more reliable and maintainable.<\/p>\n<p>TypeScript is a statically typed superset of JavaScript. Its main advantages are compile-time type checking, improved code quality, better IDE support, easier refactoring, interfaces, generics, and enhanced maintainability. It helps catch errors early, improves developer productivity with features like IntelliSense, and is well suited for large-scale applications and team development. That&#8217;s why frameworks like Angular are built on TypeScript.<\/p>\n<h3 class=\"PDq2pG_selectionAnchorContainer\" data-section-id=\"1m5tatj\" data-start=\"3018\" data-end=\"3044\">JavaScript vs TypeScript<\/h3>\n<div class=\"TyagGW_tableContainer\">\n<div class=\"group TyagGW_tableWrapper flex flex-col-reverse w-fit\" tabindex=\"-1\">\n<table class=\"w-fit min-w-(--thread-content-width)\" data-start=\"3046\" data-end=\"3388\">\n<thead data-start=\"3046\" data-end=\"3073\">\n<tr data-start=\"3046\" data-end=\"3073\">\n<th class=\"last:pe-10\" data-start=\"3046\" data-end=\"3059\" data-col-size=\"sm\">JavaScript<\/th>\n<th class=\"last:pe-10\" data-start=\"3059\" data-end=\"3073\" data-col-size=\"sm\">TypeScript<\/th>\n<\/tr>\n<\/thead>\n<tbody data-start=\"3102\" data-end=\"3388\">\n<tr data-start=\"3102\" data-end=\"3142\">\n<td data-start=\"3102\" data-end=\"3122\" data-col-size=\"sm\">Dynamically typed<\/td>\n<td data-start=\"3122\" data-end=\"3142\" data-col-size=\"sm\">Statically typed<\/td>\n<\/tr>\n<tr data-start=\"3143\" data-end=\"3206\">\n<td data-start=\"3143\" data-end=\"3169\" data-col-size=\"sm\">Errors found at runtime<\/td>\n<td data-start=\"3169\" data-end=\"3206\" data-col-size=\"sm\">Many errors found at compile time<\/td>\n<\/tr>\n<tr data-start=\"3207\" data-end=\"3246\">\n<td data-start=\"3207\" data-end=\"3223\" data-col-size=\"sm\">No interfaces<\/td>\n<td data-start=\"3223\" data-end=\"3246\" data-col-size=\"sm\">Supports interfaces<\/td>\n<\/tr>\n<tr data-start=\"3247\" data-end=\"3282\">\n<td data-start=\"3247\" data-end=\"3261\" data-col-size=\"sm\">No generics<\/td>\n<td data-start=\"3261\" data-end=\"3282\" data-col-size=\"sm\">Supports generics<\/td>\n<\/tr>\n<tr data-start=\"3283\" data-end=\"3327\">\n<td data-start=\"3283\" data-end=\"3302\" data-col-size=\"sm\">Less IDE support<\/td>\n<td data-start=\"3302\" data-end=\"3327\" data-col-size=\"sm\">Excellent IDE support<\/td>\n<\/tr>\n<tr data-start=\"3328\" data-end=\"3388\">\n<td data-start=\"3328\" data-end=\"3355\" data-col-size=\"sm\">Better for small scripts<\/td>\n<td data-start=\"3355\" data-end=\"3388\" data-col-size=\"sm\">Better for large applications<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<pre class=\"cm-content q9tKkq_readonly m-0\"><code><\/code><\/pre>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>1.What is JSX in React? JSX stands for JavaScript XML. It is a syntax extension for JavaScript used in React to write HTML-like code inside JavaScript. Why Use JSX? JSX makes it easier to build UI in React by letting you write components using syntax that looks like HTML, but is actually converted to JavaScript&#8230;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[16],"tags":[],"class_list":["post-54","post","type-post","status-publish","format-standard","hentry","category-blog-post"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.6 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>React Questions - Smita Bharat Blog<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/smitabharat.com\/blog\/react-questions\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"React Questions - Smita Bharat Blog\" \/>\n<meta property=\"og:description\" content=\"1.What is JSX in React? JSX stands for JavaScript XML. It is a syntax extension for JavaScript used in React to write HTML-like code inside JavaScript. Why Use JSX? JSX makes it easier to build UI in React by letting you write components using syntax that looks like HTML, but is actually converted to JavaScript...\" \/>\n<meta property=\"og:url\" content=\"https:\/\/smitabharat.com\/blog\/react-questions\/\" \/>\n<meta property=\"og:site_name\" content=\"Smita Bharat Blog\" \/>\n<meta property=\"article:published_time\" content=\"2026-07-02T10:57:25+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2026-08-01T18:13:08+00:00\" \/>\n<meta name=\"author\" content=\"Smita\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Smita\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"5 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/react-questions\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/react-questions\\\/\"},\"author\":{\"name\":\"Smita\",\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/#\\\/schema\\\/person\\\/8d82457aaa3ced63e3f875cb5a31ce4c\"},\"headline\":\"React Questions\",\"datePublished\":\"2026-07-02T10:57:25+00:00\",\"dateModified\":\"2026-08-01T18:13:08+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/react-questions\\\/\"},\"wordCount\":1108,\"commentCount\":0,\"articleSection\":[\"Blog Post\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/smitabharat.com\\\/blog\\\/react-questions\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/react-questions\\\/\",\"url\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/react-questions\\\/\",\"name\":\"React Questions - Smita Bharat Blog\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/#website\"},\"datePublished\":\"2026-07-02T10:57:25+00:00\",\"dateModified\":\"2026-08-01T18:13:08+00:00\",\"author\":{\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/#\\\/schema\\\/person\\\/8d82457aaa3ced63e3f875cb5a31ce4c\"},\"breadcrumb\":{\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/react-questions\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/smitabharat.com\\\/blog\\\/react-questions\\\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/react-questions\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"React Questions\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/#website\",\"url\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/\",\"name\":\"Smita Bharat Blog\",\"description\":\"\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/#\\\/schema\\\/person\\\/8d82457aaa3ced63e3f875cb5a31ce4c\",\"name\":\"Smita\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/c2cc9a654a17e3944ea74c7317b81fa65c28ba7d50a629a551b0c9b321308883?s=96&d=mm&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/c2cc9a654a17e3944ea74c7317b81fa65c28ba7d50a629a551b0c9b321308883?s=96&d=mm&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/c2cc9a654a17e3944ea74c7317b81fa65c28ba7d50a629a551b0c9b321308883?s=96&d=mm&r=g\",\"caption\":\"Smita\"},\"sameAs\":[\"https:\\\/\\\/smitabharat.com\\\/blog\"],\"url\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/author\\\/smita_bharat_wp\\\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"React Questions - Smita Bharat Blog","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/smitabharat.com\/blog\/react-questions\/","og_locale":"en_US","og_type":"article","og_title":"React Questions - Smita Bharat Blog","og_description":"1.What is JSX in React? JSX stands for JavaScript XML. It is a syntax extension for JavaScript used in React to write HTML-like code inside JavaScript. Why Use JSX? JSX makes it easier to build UI in React by letting you write components using syntax that looks like HTML, but is actually converted to JavaScript...","og_url":"https:\/\/smitabharat.com\/blog\/react-questions\/","og_site_name":"Smita Bharat Blog","article_published_time":"2026-07-02T10:57:25+00:00","article_modified_time":"2026-08-01T18:13:08+00:00","author":"Smita","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Smita","Est. reading time":"5 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/smitabharat.com\/blog\/react-questions\/#article","isPartOf":{"@id":"https:\/\/smitabharat.com\/blog\/react-questions\/"},"author":{"name":"Smita","@id":"https:\/\/smitabharat.com\/blog\/#\/schema\/person\/8d82457aaa3ced63e3f875cb5a31ce4c"},"headline":"React Questions","datePublished":"2026-07-02T10:57:25+00:00","dateModified":"2026-08-01T18:13:08+00:00","mainEntityOfPage":{"@id":"https:\/\/smitabharat.com\/blog\/react-questions\/"},"wordCount":1108,"commentCount":0,"articleSection":["Blog Post"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/smitabharat.com\/blog\/react-questions\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/smitabharat.com\/blog\/react-questions\/","url":"https:\/\/smitabharat.com\/blog\/react-questions\/","name":"React Questions - Smita Bharat Blog","isPartOf":{"@id":"https:\/\/smitabharat.com\/blog\/#website"},"datePublished":"2026-07-02T10:57:25+00:00","dateModified":"2026-08-01T18:13:08+00:00","author":{"@id":"https:\/\/smitabharat.com\/blog\/#\/schema\/person\/8d82457aaa3ced63e3f875cb5a31ce4c"},"breadcrumb":{"@id":"https:\/\/smitabharat.com\/blog\/react-questions\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/smitabharat.com\/blog\/react-questions\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/smitabharat.com\/blog\/react-questions\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/smitabharat.com\/blog\/"},{"@type":"ListItem","position":2,"name":"React Questions"}]},{"@type":"WebSite","@id":"https:\/\/smitabharat.com\/blog\/#website","url":"https:\/\/smitabharat.com\/blog\/","name":"Smita Bharat Blog","description":"","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/smitabharat.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/smitabharat.com\/blog\/#\/schema\/person\/8d82457aaa3ced63e3f875cb5a31ce4c","name":"Smita","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/c2cc9a654a17e3944ea74c7317b81fa65c28ba7d50a629a551b0c9b321308883?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/c2cc9a654a17e3944ea74c7317b81fa65c28ba7d50a629a551b0c9b321308883?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/c2cc9a654a17e3944ea74c7317b81fa65c28ba7d50a629a551b0c9b321308883?s=96&d=mm&r=g","caption":"Smita"},"sameAs":["https:\/\/smitabharat.com\/blog"],"url":"https:\/\/smitabharat.com\/blog\/author\/smita_bharat_wp\/"}]}},"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/smitabharat.com\/blog\/wp-json\/wp\/v2\/posts\/54","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/smitabharat.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/smitabharat.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/smitabharat.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/smitabharat.com\/blog\/wp-json\/wp\/v2\/comments?post=54"}],"version-history":[{"count":4,"href":"https:\/\/smitabharat.com\/blog\/wp-json\/wp\/v2\/posts\/54\/revisions"}],"predecessor-version":[{"id":66,"href":"https:\/\/smitabharat.com\/blog\/wp-json\/wp\/v2\/posts\/54\/revisions\/66"}],"wp:attachment":[{"href":"https:\/\/smitabharat.com\/blog\/wp-json\/wp\/v2\/media?parent=54"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/smitabharat.com\/blog\/wp-json\/wp\/v2\/categories?post=54"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/smitabharat.com\/blog\/wp-json\/wp\/v2\/tags?post=54"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}