FBISE, NCP & NBF-aligned resources for Classes 9–12
Browse by Class
Browse by Type
Computer Chapter 3 : Topic 5.1
Code written outside of a function is hard to test
1 / 8
A student writes JavaScript code where variables and logic are written directly in the script outside any function. Why is this approach considered difficult for debugging?
Reasoning: Code outside functions runs globally, making it harder to test or isolate individual parts during debugging.
2 / 8
A programmer is debugging a JavaScript program and wants to test a specific block of code repeatedly. What is the best practice for making this easier?
Reasoning: Functions allow modular testing, making debugging easier by isolating logic into reusable blocks.
3 / 8
What is the main disadvantage of writing JavaScript code outside functions when trying to locate errors?
Reasoning: Global scope mixes all code together, making it harder to identify where an error occurs.
4 / 8
A student is unable to find where a bug occurs in a long JavaScript file. Which debugging strategy would be most effective?
Reasoning: Breaking code into functions allows isolated testing, making it easier to identify and fix errors.
5 / 8
Which coding practice improves debugging by allowing individual testing of features in JavaScript programs?
Reasoning: Functions modularize code, enabling separate testing of each logical unit.
6 / 8
A programmer uses console.log() statements during development. What is the primary purpose of this debugging technique?
Reasoning: console.log() helps track variable values and program execution flow for debugging purposes.
7 / 8
Why is it recommended to avoid writing all JavaScript logic directly in the global scope?
Reasoning: Global code becomes harder to manage, test, and debug because everything is mixed together.
8 / 8
During debugging, a student wraps a problematic code section inside a function and tests it separately. What concept is being applied?
Reasoning: Encapsulation through functions helps isolate code, making debugging and testing more controlled.
Your score is
Restart quiz