Classes And Modules — Part 2 MCQs with Explanations
Practice high-yield Programming & Software Development MCQs on Classes And Modules — Part 2 with worked academic solutions for FPSC, PPSC, NTS, NITB, PTS.
Questions
28
Difficulty Level
Exam-Level
Target Exams
FPSC, PPSC, NTS...
Estimated Time
34 mins
Exam-Level FPSC PPSC NTS NITB PTS
Verified for Commission Syllabus • Oct 14, 2026
28
Verified Practice Questions
Interactive test mode with detailed academic worked solutions
Live Progress|0/28 answered
✓0 correct
✗0 wrong
0% score
🎉 Set complete! All 28 questions answered.
Question 1 of 28
★ FPSC
★ PPSC
★ FPSC
★ PPSC
Why was “The Good Parts” designed as a language subset in JavaScript?
Correct Answer: Option D — To improve programmer productivity
Detailed Academic Explanation:
The Good Parts is a language subset designed for aesthetic reasons and with a desire to improve programmer productivity. There is a larger class of subsets that have been designed for the purpose of safely running untrusted JavaScript in a secure container or “sandbox”.
💡Key Conceptual Anchor:Classes And Modules
Question 2 of 28
★ FPSC
★ PPSC
★ FPSC
★ PPSC
Which is the subset that is a secure container designed for the purpose of safely running untrusted JavaScript?
Correct Answer: Option A — Sandbox
Detailed Academic Explanation:
There is a larger class of subsets that have been designed for the purpose of safely running untrusted JavaScript in a secure container or “sandbox”.
💡Key Conceptual Anchor:Classes And Modules
Question 3 of 28
★ FPSC
★ PPSC
★ FPSC
★ PPSC
Why is the this keyword forbidden in JavaScript?
Correct Answer: Option C — Functions should not access the global objects
Detailed Academic Explanation:
The this keyword is forbidden or restricted because functions (in non-strict mode) can access the global object through this. Preventing access to the global object is one of the key purposes of any sandboxing system.
💡Key Conceptual Anchor:Classes And Modules
Question 4 of 28
★ FPSC
★ PPSC
★ FPSC
★ PPSC
Which are the two functions that are not allowed in any secure subset?
Correct Answer: Option B — eval() and the Function() constructor
Detailed Academic Explanation:
eval() and the Function() constructor are not allowed in any secure subset because they allow the execution of arbitrary strings of code, and these strings cannot be statically analyzed.
💡Key Conceptual Anchor:Classes And Modules
Question 5 of 28
★ FPSC
★ PPSC
★ FPSC
★ PPSC
Which is the object that defines methods that allow complete control over page content?
Correct Answer: Option A — The client-side document object
Detailed Academic Explanation:
The client-side document object defines methods that allow complete control over page content.
💡Key Conceptual Anchor:Classes And Modules
Question 6 of 28
★ FPSC
★ PPSC
★ FPSC
★ PPSC
Which was one of the first security subsets proposed?
Correct Answer: Option D — ADSafe
Detailed Academic Explanation:
ADsafe was one of the first security subsets proposed) It was created by Douglas Crockford (who also defined The Good Parts subset).ADsafe relies on static verification only, and it uses JSLint as its verifier. It forbids access to most global variables and defines an ADSAFE variable that provides access to a secure API, including special-purpose DOM methods. ADsafe is not in wide use, but it was an influential proof-of-concept that influenced other secure subsets.
💡Key Conceptual Anchor:Classes And Modules
Question 7 of 28
★ FPSC
★ PPSC
★ FPSC
★ PPSC
Which is the subset that transforms web content into secure modules that can be safely hosted on a web page?
Correct Answer: Option D — dojox.secure
Detailed Academic Explanation:
Caja is Google’s open-source secure subset. Caja (Spanish for “box”) defines two language subsets. Cajita (“little box”) is a narrow subset like that used by ADsafe and dojox.secure. Valija (“suitcase” or “baggage”) is a much broader language that is close to regular ECMAScript 5 strict mode (with the removal of eval()). Caja itself is the name of the compiler that transforms (or “cajoles”) web content (HTML, CSS, and JavaScript code) into secure modules that can be safely hosted on a web page without being able to affect the page as a whole or other modules on the page.
💡Key Conceptual Anchor:Classes And Modules
Question 8 of 28
★ FPSC
★ PPSC
★ FPSC
★ PPSC
Consider the following code snippet const pi = 3.14 ; var pi = 4 ; console . log ( pi ) ; What will be the output for the above code snippet?
Correct Answer: Option A — This will flash an error
Detailed Academic Explanation:
The above code snippet will flash an error. Attempts to alter the value or re-declaration causes errors.
💡Key Conceptual Anchor:Classes And Modules
Question 9 of 28
★ FPSC
★ PPSC
★ FPSC
★ PPSC
The let keyword can be used
Correct Answer: Option D — all of the mentioned
Detailed Academic Explanation:
The let keyword can be used in four ways : 1. as a variable declaration like var; 2. in a for or for/in loop, as a substitute for var; 3. as a block statement, to define new variables and explicitly delimit their scope; and 4. to define variables that are scoped to a single expression.
💡Key Conceptual Anchor:Classes And Modules
Question 10 of 28
★ FPSC
★ PPSC
★ FPSC
★ PPSC
The main difference between the variables declared with var and with let is
Correct Answer: Option B — let is confined to a particular function but var is not
Detailed Academic Explanation:
Variables declared with var are defined throughout the enclosing function. Variables declared with let are defined only within the closest enclosing block (and any blocks nested within it, of course).
💡Key Conceptual Anchor:Classes And Modules
Question 11 of 28
★ FPSC
★ PPSC
★ FPSC
★ PPSC
Consider the following code snippet function oddsums ( n ) { let total = 0 , result = [] ; for( let x = 1 ; x <= n; x ++ ) { let odd = 2 * x - 1 ; total += odd; result . push ( total ) ; } return result; } What would be the output if oddsums ( 5 ) ; is executed afted the above code snippet ?
Correct Answer: Option A — Returns [1,4,9,16,25]
Detailed Academic Explanation:
The above code returns 1,4,9,16,25 which is the square of the first five natural numbers. Notice the usage of let keyword in the above code snippet.
💡Key Conceptual Anchor:Classes And Modules
Question 12 of 28
★ FPSC
★ PPSC
★ FPSC
★ PPSC
Consider the following code snippet console . log ( p ) If p is not defined, what would be the result or type of error?
Correct Answer: Option C — ReferenceError
Detailed Academic Explanation:
In the above code snippet, p is not defined. Hence, it gives a ReferenceError.
💡Key Conceptual Anchor:Classes And Modules
Question 13 of 28
★ FPSC
★ PPSC
★ FPSC
★ PPSC
Consider the following code snippet let x = x + 1 ; console . log ( x ) ; What will be the result for the above code snippet?
Correct Answer: Option D — NaN
Detailed Academic Explanation:
Since x is a let variable and since x is undefined, so x+1 is NaN. Thus, the above code snippet prints NaN.
💡Key Conceptual Anchor:Classes And Modules
Question 14 of 28
★ FPSC
★ PPSC
★ FPSC
★ PPSC
Consider the following code snippet [ x,y ]=[ y,x ] ; What is the result of the above code snippet?
Correct Answer: Option C — Flashes an error
Detailed Academic Explanation:
The above code snippet swaps the value of the two variables.
💡Key Conceptual Anchor:Classes And Modules
Question 15 of 28
★ FPSC
★ PPSC
★ FPSC
★ PPSC
Which looping statement allows XML tags to appear in JavaScript programs and adds API for operating on XML data?
Correct Answer: Option C — for/each loop
Detailed Academic Explanation:
The for/each loop is a new looping statement standardized by E4X. E4X (ECMAScript for XML) is a language extension that allows XML tags to appear literally in JavaScript programs and adds syntax and API for operating on XML data.
💡Key Conceptual Anchor:Classes And Modules
Question 16 of 28
★ FPSC
★ PPSC
★ FPSC
★ PPSC
Which exception does the Iterators throw from their next() method when there are no more values to iterate, that work on finite collections ?
Correct Answer: Option D — StopIteration
Detailed Academic Explanation:
Iterators that work on finite collections throw StopIteration from their next() method when there are no more values to iterate. StopIteration is a property of the global object in JavaScript 1.7. Its value is an ordinary object (with no properties of its own) that is reserved for this special purpose of terminating iterations. Note, in particular,that StopIteration is not a constructor function like TypeError() or RangeError().
💡Key Conceptual Anchor:Classes And Modules
Question 17 of 28
★ FPSC
★ PPSC
★ FPSC
★ PPSC
Which method of the iterable object returns an iterator object for the collection?
Correct Answer: Option B — _iterator_()
Detailed Academic Explanation:
An iterable object represents a collection of values that can be iterated. An iterable object must define a method named __iterator__() (with two underscores at the start and end of the name) which returns an iterator object for the collection.
💡Key Conceptual Anchor:Classes And Modules
Question 18 of 28
★ FPSC
★ PPSC
★ FPSC
★ PPSC
Consider the following code snippet let succ = function ( x ) x + 1 , yes = function () true , no = function () false ; What convenience does the above code snippet provide?
Correct Answer: Option A — Functional behaviour
Detailed Academic Explanation:
The functions defined in this way behave exactly like functions defined with curly braces and the return keyword.
💡Key Conceptual Anchor:Classes And Modules
Question 19 of 28
★ FPSC
★ PPSC
★ FPSC
★ PPSC
Consider the following code snippet data . sort (function( a,b ) ,b - a ) ; What does the above code do?
Correct Answer: Option D — Sort in reverse numerical order
Detailed Academic Explanation:
The above code snippet sorts an array in reverse numerical order.
💡Key Conceptual Anchor:Classes And Modules
Question 20 of 28
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What is the code to be used to trim whitespaces ?
Correct Answer: Option A — let trimmed = (l.trim() for (l in lines))
Detailed Academic Explanation:
We can use the above code to trim whitespaces and filter out comments and blank lines.
💡Key Conceptual Anchor:Classes And Modules
Question 21 of 28
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What will be the reaction when a catch clause has no conditionals ?
Correct Answer: Option C — Takes it to be true
Detailed Academic Explanation:
If a catch clause has no conditional, it behaves as if it has the conditional if true, and it is always triggered if no clause before it was triggered.
💡Key Conceptual Anchor:Classes And Modules
Question 22 of 28
★ FPSC
★ PPSC
★ FPSC
★ PPSC
When will the finally block be called?
Correct Answer: Option D — None of the mentioned
Detailed Academic Explanation:
A finally block is called after try-catch execution.
💡Key Conceptual Anchor:Classes And Modules
Question 23 of 28
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What is the return type of typeof for standard JavaScript objects?
Correct Answer: Option B — object
Detailed Academic Explanation:
The typeof operator returns “object” for all standard JavaScript objects as functions are, and the typeof operator returns “xml”.
💡Key Conceptual Anchor:Classes And Modules
Question 24 of 28
★ FPSC
★ PPSC
★ FPSC
★ PPSC
Which of the following is the descendant operator?
Correct Answer: Option B — …
Detailed Academic Explanation:
The .. operator is the descendant operator; you can use it in place of the normal . member-access operator : var names = pt .. name;
💡Key Conceptual Anchor:Classes And Modules
Question 25 of 28
★ FPSC
★ PPSC
★ FPSC
★ PPSC
Which of the following is an example to perform the most common XML manipulations using the XML objects invocation?
Correct Answer: Option A — insertChildBefore()
Detailed Academic Explanation:
E4X is designed so that you can perform most common XML manipulations using language syntax. E4X also defines methods you can invoke on XML objects. Here, for example, is the insertChildBefore() method:
💡Key Conceptual Anchor:Classes And Modules
Question 26 of 28
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What is the code required to delete all “weight” tags?
Correct Answer: Option D — delete pt..weight
Detailed Academic Explanation:
Removing attributes and tags is very easy with the standard delete operator : delete pt .. weight; //delete all tags
💡Key Conceptual Anchor:Classes And Modules
Question 27 of 28
★ FPSC
★ PPSC
★ FPSC
★ PPSC
The snippet that filters the filtered set is
Correct Answer: Option A — var t=new FilteredSet(s, {function(s) {return !(x instanceof Set);})
Detailed Academic Explanation:
var t=new FilteredSet(s, {function(s) {return !(x instanceof Set);}) is the correct answer to “The snippet that filters the filtered set is”. This question is standard in competitive examination syllabi for Classes And Modules.
💡Key Conceptual Anchor:Classes And Modules
Question 28 of 28
★ FPSC
★ PPSC
★ FPSC
★ PPSC
Which method to use while working with XML fragments, instead of XML()?
Correct Answer: Option C — XMLList()
Detailed Academic Explanation:
XMLList() is the correct answer to “Which method to use while working with XML fragments, instead of XML()”. This question is standard in competitive examination syllabi for Classes And Modules.
💡Key Conceptual Anchor:Classes And Modules
✓Link copied to clipboard
Continue Your Practice
Advance Html — Part 1
Master the next curriculum module with 40 exam-standard MCQs.
💡Examiner's Advisory for Programming & Software Development
In competitive commission exams (FPSC, PPSC, KPPSC, SPSC, CSS, PMS), questions are frequently phrased with distractor options designed to catch rote learners. Whenever you answer an MCQ, read the Detailed Academic Explanation and Conceptual Anchor to understand why the remaining options are incorrect.