Class 10 Chapter 3: Short Question Answers (SRQs)
4) How is unit testing used when adding a function to an already written program?
Answer:
Unit testing helps verify that a new function works properly without breaking the existing code. When adding a new function, you write small tests (called unit tests) to check each part of that function. If the tests pass, it means the function behaves as expected. This saves time and helps detect bugs early in the development process.
5) Enlist 3 key differences between Array and List.
Answer:
| Feature | List (JavaScript Array) | Array (TypedArray) |
|---|---|---|
| Data Types | Can store mixed types (numbers, strings, objects) | Stores only one data type (typed: int, float, etc.) |
| Speed | Slower for large datasets or numerical computation | Faster for numerical operations (especially in WebGL, etc.) |
| Memory Usage | Higher memory usage due to dynamic typing | Optimized, lower memory footprint |
| Usage | General-purpose list operations | Best for numerical and performance-critical operations |
| Module Needed | Built-in (Array) | Built-in (TypedArray, no extra modules) |
6) How are breakpoints useful in debugging? Elaborate with the help of an example.
Answer:
Breakpoints pause the code execution at a specific line while running, allowing the programmer to inspect variable values and program flow. This helps find where errors occur.
Example: Suppose a loop isn’t giving the correct output. You can set a breakpoint inside the loop and run the program step-by-step. This way, you can observe whether the loop works correctly and check the value of each variable during each iteration.