Intoduction to React Flashcards

1
Q

What is the DOM in JavaScript?

A

The DOM (Document Object Model) is a programming interface for web pages, allowing you to change, read, and update the content of a document using JavaScript.

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

Name the three parts of the DOM and their meanings.

A

Document: Represents the web page content (e.g., text, images, forms).
Object: Structured containers representing elements.
Model: Logical, hierarchical representation like a family tree.

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

List three methods for retrieving elements in the DOM.

A

getElementById(id)
getElementsByClassName(className)
querySelector(selector)

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

How do you add a new element to the DOM?

A

Use createElement(tagName) to create a new element.
Append it with appendChild(node).

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

What is React?

A

React is an open-source JavaScript library developed by Facebook for building user interfaces and managing the view layer of web applications.

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

Why use React? List three benefits.

A

Component-Based Architecture
Efficient Virtual DOM
Reusability and Composability

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

What is the difference between the Virtual DOM and the Real DOM?

A

Virtual DOM: Lightweight, in-memory representation.
Real DOM: The actual structure of a web page.

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

What is JSX?

A

JSX is a syntax extension for JavaScript, allowing HTML-like markup in JS files. It produces React elements after compilation.

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

What is the difference between functional and class-based components in React?

A

Functional Components: Stateless, render UI, use props.
Class-Based Components: Stateful, implement logic, and use lifecycle methods.

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

How do you set up a new React project with Vite?

A

Run npm create vite@latest.
Navigate to the project directory (cd vite-project).
Install dependencies (npm install).
Start the development server (npm run dev).

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

What are the characteristics of JSX?

A

Uses {} for embedding JS expressions.
Multi-line HTML requires parentheses.
Follows XML rules and camelCase for attributes.

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

Name three ways to style elements in React.

A

CSS Classes: Use className.
Inline Styles: Use the style attribute.
Styled Components: Install with npm i styled-components.

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

What does React Router enable in React applications?

A

React Router enables navigation between different pages in a React application.

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