Web Programming Frontend Frameworks and Tools 2 — Questions and Answers
Question 1: In React, what is the useState hook used for?
- Fetching data from APIs
- Adding and managing local state in functional components (Correct answer)
- Routing between pages
- Connecting to a database
Correct answer: Adding and managing local state in functional components
The useState hook allows functional components to declare and manage local state variables, returning the current state and a function to update it.
Question 2: What is the purpose of version control in web development?
- To manage database versions
- To track changes to code over time and enable collaboration (Correct answer)
- To version API endpoints
- To update npm packages
Correct answer: To track changes to code over time and enable collaboration
Version control systems like Git track changes to source code over time, enable collaboration, allow rollback to previous states, and support branching workflows.
Question 3: What is TypeScript's primary advantage over plain JavaScript?
- Faster execution speed
- Smaller file sizes
- Static type checking that catches errors at compile time (Correct answer)
- Built-in HTTP client
Correct answer: Static type checking that catches errors at compile time
TypeScript adds optional static typing to JavaScript, allowing type errors to be caught during development before the code runs in the browser.
Question 4: What is the purpose of ESLint in a web project?
- To bundle JavaScript files
- To analyze JavaScript code for errors and enforce coding style rules (Correct answer)
- To minify CSS
- To run unit tests
Correct answer: To analyze JavaScript code for errors and enforce coding style rules
ESLint is a static code analysis tool that identifies problematic patterns in JavaScript code and enforces configurable coding standards.
Question 5: In Angular, what is a component decorator (@Component) used for?
- To apply CSS styles
- To define metadata for an Angular component including its template and selector (Correct answer)
- To inject dependencies
- To create HTTP interceptors
Correct answer: To define metadata for an Angular component including its template and selector
The @Component decorator in Angular marks a class as a component and provides configuration metadata including the HTML template, CSS styles, and selector.
Question 6: What is the purpose of a .gitignore file?
- To block certain users from Git access
- To specify files and directories that Git should not track (Correct answer)
- To merge Git branches automatically
- To configure Git commit messages
Correct answer: To specify files and directories that Git should not track
The .gitignore file tells Git which files and directories to exclude from version control tracking, commonly used for node_modules, build outputs, and secret files.
In React, what is the useState hook used for?