Unit 6 - Practice Quiz

INT219 50 Questions
0 Correct 0 Wrong 50 Left
0/50

1 Which TypeScript feature allows you to create a reusable component or function that works with a variety of types rather than a single one?

A. Interfaces
B. Generics
C. Decorators
D. Modules

2 In TypeScript, what is the primary difference between an interface and a type alias regarding declaration merging?

A. Type aliases support declaration merging, but interfaces do not.
B. Interfaces support declaration merging, allowing you to add members to an existing interface by redeclaring it.
C. Both support declaration merging equally.
D. Neither supports declaration merging.

3 Which TypeScript Utility Type constructs a type with all properties of Type T set to optional?

A. Required<T>
B. Pick<T, K>
C. Partial<T>
D. Omit<T, K>

4 When defining the type for a React Functional Component's props, which syntax is generally preferred for explicit typing without using the React.FC type?

A. function MyComponent(props: any) { ... }
B. function MyComponent({ name }: { name: string }) { ... }
C. const MyComponent = (props) => { ... }
D. function MyComponent<T>(props: T) { ... }

5 What is the purpose of the unknown type in TypeScript?

A. It is identical to any.
B. It represents a value that can be anything, but requires type checking/narrowing before operations can be performed on it.
C. It represents a value that is strictly null or undefined.
D. It is used to define unreachable code.

6 In the context of API typing, what is a Data Transfer Object (DTO)?

A. A database schema definition.
B. An object that carries data between processes, strictly typed to match the API response structure.
C. A function used to fetch data.
D. A React component for displaying data.

7 Which tsconfig.json compiler option enables a wide range of type checking behavior that results in stronger guarantees of program correctness?

A. "allowJs": true
B. "strict": true
C. "target": "ES6"
D. "module": "commonjs"

8 What is the main benefit of using Static Code Analysis tools like ESLint in a frontend project?

A. To compile TypeScript into JavaScript.
B. To bundle CSS and JavaScript files.
C. To identify programmatic errors and stylistic issues without executing the code.
D. To run unit tests automatically.

9 Given the following type definition, what is Status?

typescript
type Status = "loading" | "success" | "error";

A. A String Enum
B. A String Literal Union
C. A Tuple
D. An Intersection Type

10 When typing a useRef hook for an HTML Input element in React, which syntax is correct?

A. const inputRef = useRef<HTMLDivElement>(null);
B. const inputRef = useRef<HTMLInputElement>(null);
C. const inputRef = useRef<HTMLElement>(null);
D. const inputRef = useRef(null);

11 What is the purpose of Source Maps in a web development debugging workflow?

A. To map IP addresses to geographic locations.
B. To map minified/transpiled code back to the original source code for easier debugging.
C. To visualize the folder structure of the project.
D. To map CSS classes to HTML elements.

12 Which of the following is a key characteristic of Unit Testing?

A. It tests the entire application flow from end-to-end.
B. It tests individual functions or components in isolation.
C. It requires a live database connection.
D. It is performed manually by QA engineers.

13 Which mathematical operator is used to create an Intersection Type in TypeScript?

A. The pipe |
B. The ampersand &
C. The plus +
D. The asterisk *

14 In the context of Code Quality, what does the DRY principle stand for?

A. Do Repeat Yourself
B. Don't Repeat Yourself
C. Data Render Yield
D. Deploy Review Yak

15 How can you type the event object in a React onChange handler for an input field?

A. event: Event
B. event: React.ChangeEvent<HTMLInputElement>
C. event: HTMLElement
D. event: any

16 What is the result of using the Omit<T, K> utility type?

A. It constructs a type by picking the set of properties K from T.
B. It constructs a type by picking all properties from T and then removing K.
C. It makes all properties in T readonly.
D. It merges type T and type K.

17 Which tool is commonly used to enforce code formatting styles (indentation, quotes, semicolons) automatically?

A. Jest
B. Prettier
C. Webpack
D. Babel

18 In a TypeScript project, what file extension is required for files that contain JSX syntax?

A. .ts
B. .js
C. .jsx
D. .tsx

19 What is Cyclomatic Complexity?

A. A measure of how many lines of code are in a project.
B. A quantitative measure of the number of linearly independent paths through a program's source code.
C. The number of npm dependencies a project has.
D. The time it takes for a page to load.

20 Which TypeScript configuration option allows importing JavaScript files into a TypeScript project during migration?

A. "allowJs": true
B. "checkJs": true
C. "noEmit": true
D. "jsx": "react"

21 What is Mocking in the context of unit testing?

A. Making fun of bad code.
B. Replacing a real dependency (like an API call) with a simulated object to isolate the unit under test.
C. Running tests in a random order.
D. Ignoring failed tests.

22 Which generic constraint syntax ensures that a generic type T must contain a specific property length?

A. function fn<T extends { length: number }>(arg: T)
B. function fn<T implements { length: number }>(arg: T)
C. function fn<T : { length: number }>(arg: T)
D. function fn<T>(arg: T.length)

23 What is the primary purpose of Husky in a web development environment?

A. To optimize images.
B. To manage Git hooks, such as running linters or tests before a commit.
C. To deploy applications to the cloud.
D. To format CSS.

24 In React Testing Library, what is the best practice for selecting elements to test?

A. Select by CSS class names (.container).
B. Select by internal component state.
C. Select by ID (#submit-btn).
D. Select by how the user interacts with them (e.g., getByRole, getByText).

25 What is the definition of Technical Debt?

A. Money owed for software licenses.
B. The implied cost of additional rework caused by choosing an easy solution now instead of using a better approach that would take longer.
C. The monthly cost of cloud hosting.
D. The size of the node_modules folder.

26 Which type of test verifies that the system meets external requirements and achieves its goals, usually testing the entire application stack?

A. Unit Testing
B. Integration Testing
C. End-to-End (E2E) Testing
D. Static Analysis

27 Which TypeScript feature allows you to tell the compiler "I know this variable is type X, trust me"?

A. Type Guard
B. Type Assertion (as syntax)
C. Type Inference
D. Type Alias

28 What is the result of accessing a property on a variable typed as any?

A. A compilation error.
B. A runtime error.
C. TypeScript allows it without error, skipping type checking.
D. It returns null.

29 Which SOLID principle suggests that a class (or module/function) should have one, and only one, reason to change?

A. Single Responsibility Principle (SRP)
B. Open/Closed Principle (OCP)
C. Liskov Substitution Principle (LSP)
D. Interface Segregation Principle (ISP)

30 What is the benefit of using Discriminated Unions in TypeScript for state management (e.g., Redux actions or loading states)?

A. They allow any string to be used as a type.
B. They use a common literal property (the discriminant) to let TypeScript narrow down the exact object shape in a switch statement.
C. They remove the need for interfaces.
D. They automatically generate documentation.

31 In the browser console, which method displays data as an interactive table?

A. console.log()
B. console.error()
C. console.table()
D. console.dir()

32 How do you define an optional property in a TypeScript interface?

A. name: string?
B. name?: string
C. optional name: string
D. name: string | optional

33 Which of the following describes Regression Testing?

A. Testing a new feature for the first time.
B. Testing to confirm that a recent program or code change has not adversely affected existing features.
C. Testing the user interface design.
D. Testing the speed of the API.

34 What is the purpose of the ReturnType<Type> utility in TypeScript?

A. To force a function to return a specific type.
B. To extract the return type of a function type.
C. To return the type of a variable at runtime.
D. To create a recursive type.

35 When refactoring code, what is the primary goal?

A. To change the functionality of the application.
B. To fix bugs.
C. To restructure internal code without changing external behavior to improve readability or maintainability.
D. To add new features.

36 Which TypeScript syntax allows a value to be one of several types (e.g., string OR number)?

A. Intersection Type string & number
B. Union Type string | number
C. Generic Type string, number
D. Tuple [string, number]

37 In a tsconfig.json, what does "noImplicitAny": true do?

A. It automatically converts any types to string.
B. It raises an error on expressions and declarations with an implied any type.
C. It removes all any types from the code.
D. It allows variables to be declared without types.

38 What is a Snapshot Test in Jest?

A. A test that takes a screenshot of the browser.
B. A test that compares the rendered output of a component (serialized to a file) against a previously stored version.
C. A test that runs only once.
D. A test that records the database state.

39 When debugging, what does the Step Over command do?

A. It enters the function call on the current line.
B. It executes the current line and pauses at the next line in the current function, skipping over internal function calls.
C. It resumes execution until the next breakpoint.
D. It restarts the debugger.

40 What is the strict TypeScript type for children in a React component if you expect only React elements (not text or numbers)?

A. React.ReactNode
B. React.ReactElement
C. JSX.Element
D. any

41 What is Code Coverage?

A. The percentage of lines of code covered by comments.
B. A metric used to measure the percentage of source code executed when a test suite runs.
C. The number of browsers the code supports.
D. The amount of documentation available.

42 Which TS utility type would you use to create a type where keys are strings and values are numbers?

A. Map<string, number>
B. Record<string, number>
C. Object<string, number>
D. Array<number>

43 What is the primary purpose of .d.ts files?

A. To store runtime logic.
B. To store configuration settings.
C. To provide type definitions for JavaScript code so TypeScript can understand it.
D. To store unit tests.

44 In the context of Clean Code, what does it mean to avoid Magic Numbers?

A. Do not use numbers in variable names.
B. Replace unnamed numerical constants with named constants that explain their meaning.
C. Do not use math libraries.
D. Use hexadecimal instead of decimal.

45 Which keyword is used to conditionally select types in TypeScript (often called generic conditional types)?

A. if
B. switch
C. extends (ternary syntax)
D. typeof

46 Which of the following creates a read-only array in TypeScript?

A. const arr = [1, 2, 3]
B. readonly number[] or ReadonlyArray<number>
C. final number[]
D. static number[]

47 What is the "Arrange-Act-Assert" pattern used for?

A. Structuring CSS files.
B. Structuring unit tests.
C. Structuring API endpoints.
D. Structuring git commits.

48 Which TypeScript operator checks if a property exists on an object and acts as a type guard?

A. exists
B. in
C. has
D. contains

49 How does useEffect dependency array typing help in development?

A. It prevents the effect from running.
B. It warns (via linting) if you use variables inside the effect that are not listed in the dependency array.
C. It automatically imports missing dependencies.
D. It types the return value of the effect.

50 What is the mathematical definition of Big O Notation in the context of code quality?

A. The size of the output file.
B. A representation of the complexity (time or space) of an algorithm relative to the input size , e.g., .
C. The number of objects in memory.
D. The number of errors per 1000 lines of code.