A: JSX stands for JavaScript XML. JSX allows us to write HTML elements in JavaScript and place them in the DOM without any createElement() and/or appendChild() methods. JSX makes it easier to write and add HTML in React. JSX converts HTML tags into react elements.
const myElement = <h1>I Love JSX!</h1>;
const root = ReactDOM.createRoot(document.getElementById('root'));
root.render(myElement);
const myElement = React.createElement('h1', {}, 'I do not use JSX!');
const root = ReactDOM.createRoot(document.getElementById('root'));
root.render(myElement);
A: Using JSX, you can write markup inside Javascript, providing you with a superpower to write logic and markup of a component inside a single .jsx file. JSX is easy to maintain and debug.
function greeting(user) {
//JSX
return <h1>{user}, How are you!!!</h1>;
}
A: The type
attribute specifies the type of the script. The type attribute identifies the content between the <script>
and </script>
tags. It has a Default value which is “text/javascript”.
text/javascript
: It is the basic standard of writing javascript code inside the<script>
tag.<script type="text/javascript"></script>
text/ecmascript
: this value indicates that the script is following theEcmaScript
standards.module
: This value tells the browser that the script is a module that can import or export other files or modules inside it.text/babel
: This value indicates that the script is a babel type and required bable to transpile it.text/typescript
: As the name suggest the script is written inTypeScript
.
A: The Difference is stated below:
{TitleComponent}
: This value describes theTitleComponent
as a javascript expression or a variable. The{}
can embed a javascript expression or a variable inside it.<TitleComponent/>
: This value represents a Component that is basically returning Some JSX value. In simple termsTitleComponent
a function that is returning a JSX value. A component is written inside the{< />}
expression.<TitleComponent></TitleComponent>
:<TitleComponent />
and<TitleComponent></TitleComponent>
are equivalent only when< TitleComponent />
has no child components. The opening and closing tags are created to include the child components.
<TitleComponent>
<FirstChildComponent />
<SecondChildComponent />
<ThirdChildComponent />
</TitleComponent>
<TitleComponent />