React: Core Concepts & JSX Flashcards

Subtopics: JSX syntax and expressions Babel transpilation of JSX Component structure (function vs class) ReactDOM and rendering Interview-style Questions: What is JSX and how is it compiled? Can a React component return multiple elements? (20 cards)

1
Q

What is JSX in React?

A

JSX is a syntax extension for JavaScript that lets you write HTML-like code inside React components.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

How is JSX compiled?

A

JSX is compiled by Babel into React.createElement() calls that produce React elements.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What are the benefits of using JSX?

A

JSX improves code readability and makes it easier to visualize UI structure directly within JavaScript.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What is the difference between a function component and a class component?

A

Function components are simpler and use hooks, while class components use lifecycle methods and ‘this’ context.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Can a React component return multiple elements?

A

Yes, a component can return multiple elements using fragments <>…</> or an array of elements.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What does ReactDOM.render() do?

A

ReactDOM.render() mounts a React component into the real DOM, connecting virtual DOM to browser UI.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What are the advantages of function components over class components?

A

Function components are simpler, encourage cleaner code, support hooks, and reduce boilerplate.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What are disadvantages of class components?

A

Class components are more verbose, harder to refactor, and don’t benefit from hooks without rewrites.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What is the best practice for writing reusable components?

A

Keep them pure, stateless if possible, and use props to pass data and callbacks for interaction.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What is a use case for JSX expressions?

A

Dynamic values inside UI, like displaying Hello, {userName} or conditionally rendering elements.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What is the architectural implication of using JSX?

A

JSX enables declarative UI building, improving maintainability but requiring transpilation in the toolchain.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What is the impact of JSX on performance?

A

JSX itself doesn’t impact runtime; its compiled form can affect render performance depending on structure and depth.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What are common interview questions about React JSX?

A

‘What is JSX?’, ‘How is JSX compiled?’, ‘Difference between class and function components?’, ‘How to return multiple elements?’

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

What is a potential gotcha when returning multiple JSX elements?

A

Forgetting to wrap elements in a single parent, like a div or fragment, causes syntax errors.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

What does Babel do in a React project?

A

Babel transpiles modern JavaScript and JSX into backward-compatible JavaScript that browsers can run.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

What happens if you omit React import when using JSX in older setups?

A

JSX won’t compile because React.createElement will be undefined (in older versions before React 17).

17
Q

What is the role of ReactDOM?

A

ReactDOM provides DOM-specific methods to render React components and manage updates in browser environments.

18
Q

What’s a disadvantage of heavy JSX nesting?

A

Deeply nested JSX can hurt readability and maintainability; splitting into smaller components is better.

19
Q

How does JSX improve developer experience?

A

JSX enables combining markup and logic, reducing context-switching and aligning code with UI structure.

20
Q

What is a potential error when embedding JS in JSX?

A

Not wrapping JavaScript expressions in curly braces {} or placing statements (like if or loops) directly inside JSX.