Practice high-yield Programming & Software Development MCQs on Array And Function with worked academic solutions for FPSC, PPSC, NTS, NITB, PTS.
Questions
38
Difficulty Level
Exam-Level
Target Exams
FPSC, PPSC, NTS...
Estimated Time
46 mins
Exam-Level FPSC PPSC NTS NITB PTS
Verified for Commission Syllabus • Oct 14, 2026
38
Verified Practice Questions
Interactive test mode with detailed academic worked solutions
Live Progress|0/38 answered
✓0 correct
✗0 wrong
0% score
🎉 Set complete! All 38 questions answered.
Question 1 of 38
★ FPSC
★ PPSC
★ FPSC
★ PPSC
Consider the code snippet given below var count = [ 1 ,, 3 ] ; What is the observation made?
Correct Answer: Option A — The omitted value takes “undefined”
Detailed Academic Explanation:
If you omit a value from an array literal, the omitted element is given the value.
💡Key Conceptual Anchor:Array And Function
Question 2 of 38
★ FPSC
★ PPSC
★ FPSC
★ PPSC
Consider the following code snippet var a1 = [,,,] ; var a2 = new Array ( 3 ) ; 0 in a1 0 in a2 The result would be
Correct Answer: Option A — true false
Detailed Academic Explanation:
a1 has an element with index 0 and a2 has no element with index 0.
💡Key Conceptual Anchor:Array And Function
Question 3 of 38
★ FPSC
★ PPSC
★ FPSC
★ PPSC
The pop() method of the array does which of the following task ?
Correct Answer: Option A — decrements the total length by 1
Detailed Academic Explanation:
Arrays have a pop() method (it works with push()) that reduces the length of an array by 1 but also returns the value of the deleted element.
💡Key Conceptual Anchor:Array And Function
Question 4 of 38
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What will happen if reverse() and join() methods are used simultaneously ?
Correct Answer: Option A — Reverses and stores in the same array
Detailed Academic Explanation:
The reverse() followed by a join() will reverse the respective array and will store the reversed array in the memory.
💡Key Conceptual Anchor:Array And Function
Question 5 of 38
★ FPSC
★ PPSC
★ FPSC
★ PPSC
Consider the following code snippet : var a = [] ; a . unshift ( 1 ) ; a . unshift ( 22 ) ; a . shift () ; a . unshift ( 3 , [ 4 , 5 ]) ; a . shift () ; a . shift () ; a . shift () ; The final output for the shift() is
Correct Answer: Option A — 1
Detailed Academic Explanation:
The unshift() and shift() methods behave much like push() and pop(), except that they insert and remove elements from the beginning of an array rather than from the end. unshift() adds an element or elements to the beginning of the array, shifts the existing array elements up to higher indexes to make room, and returns the new length of the array. shift() removes and returns the first element of the array, shifting all subsequent elements down one place to occupy the newly vacant space at the start of the array.
💡Key Conceptual Anchor:Array And Function
Question 6 of 38
★ FPSC
★ PPSC
★ FPSC
★ PPSC
The primary purpose of the array map() function is that it
Correct Answer: Option C — passes each element of the array on which it is invoked to the function you specify, and returns an array containing the values returned by that function
Detailed Academic Explanation:
The map() method passes each element of the array on which it is invoked to the functionyou specify, and returns an array containing the values returned by that function.
💡Key Conceptual Anchor:Array And Function
Question 7 of 38
★ FPSC
★ PPSC
★ FPSC
★ PPSC
The method or operator used to identify the array is
Correct Answer: Option D — typeof
Detailed Academic Explanation:
The typeof property is used to identify the array type.
💡Key Conceptual Anchor:Array And Function
Question 8 of 38
★ FPSC
★ PPSC
★ FPSC
★ PPSC
The function definitions in JavaScript begins with
Correct Answer: Option A — Identifier and Parantheses
Detailed Academic Explanation:
The function definitions begin with the keyword function followed by an identifier that names the function and a pair of parantheses around a comma-separated list of zero or more identifiers.
💡Key Conceptual Anchor:Array And Function
Question 9 of 38
★ FPSC
★ PPSC
★ FPSC
★ PPSC
Consider the following code snippet function printprops ( o ) { for(var p in o ) console . log ( p + ": " + o [ p ] + "n" ) ; } What will the above code snippet result ?
Correct Answer: Option B — Returns undefined
Detailed Academic Explanation:
The above code snippet returns undefined.
💡Key Conceptual Anchor:Array And Function
Question 10 of 38
★ FPSC
★ PPSC
★ FPSC
★ PPSC
When does the function name become optional in JavaScript?
Correct Answer: Option B — When the function is defined as expressions
Detailed Academic Explanation:
The function name is optional for functions defined as expressions. A function declaration statement actually declares a variable and assigns a function object to it.
💡Key Conceptual Anchor:Array And Function
Question 11 of 38
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What is the purpose of a return statement in a function?
Correct Answer: Option D — Stops executing the function and returns the value
Detailed Academic Explanation:
The return statement causes the function to stop executing and to return the value of its expression (if any) to the caller.
💡Key Conceptual Anchor:Array And Function
Question 12 of 38
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What will happen if a return statement does not have an associated expression?
Correct Answer: Option C — It returns the undefined value
Detailed Academic Explanation:
If the return statement does not have an associated expression, it returns the undefined value.
💡Key Conceptual Anchor:Array And Function
Question 13 of 38
★ FPSC
★ PPSC
★ FPSC
★ PPSC
A function with no return value is called
Correct Answer: Option A — Procedures
Detailed Academic Explanation:
Functions with no return value are sometimes called procedures.
💡Key Conceptual Anchor:Array And Function
Question 14 of 38
★ FPSC
★ PPSC
★ FPSC
★ PPSC
Consider the following code snippet function hypotenuse ( a, b ) { function square ( x ) { return x * x; } return Math . sqrt ( square ( a ) + square ( b )) ; } What does the above code result?
Correct Answer: Option A — Sum of square of a and b
Detailed Academic Explanation:
The above code snippet contains nested function in which the function hypotenuse(a,b) has another function inside its scope, function square(x). The interesting thing about nested functions is their variable scoping rules. They can acceess the parameters and variables of the function (or functions) they are nested within.
💡Key Conceptual Anchor:Array And Function
Question 15 of 38
★ FPSC
★ PPSC
★ FPSC
★ PPSC
Which of the following is the correct code for invoking a function without this keyword at all, and also too determine whether the strict mode is in effect?
Correct Answer: Option C — var strict = (function() { return !this; }())
Detailed Academic Explanation:
The above code defines and invokes a function to determine if we’re in strict mode.
💡Key Conceptual Anchor:Array And Function
Question 16 of 38
★ FPSC
★ PPSC
★ FPSC
★ PPSC
Which is an equivalent code to invoke a function m of class o that expects two arguments x and y?
Correct Answer: Option D — o.m(x,y)
Detailed Academic Explanation:
The code above is an invocation expression: it includes a function expression o.m and two argument expressions, x and y.
💡Key Conceptual Anchor:Array And Function
Question 17 of 38
★ FPSC
★ PPSC
★ FPSC
★ PPSC
Consider the following code snippet : var grand_Total =eval (" 10*10+5 ") ; The output for the above statement would be :
Correct Answer: Option C — 105 as an integer value
Detailed Academic Explanation:
Even if the string value passed as a parameter to eval does represent a numeric value the use of eval() results in an error being generated.
💡Key Conceptual Anchor:Array And Function
Question 18 of 38
★ FPSC
★ PPSC
★ FPSC
★ PPSC
Consider the following code snippet : var tensquared = ( function ( x ) {return x * x; }( 10 )) ; Will the above code work ?
Correct Answer: Option A — Yes, perfectly
Detailed Academic Explanation:
Function name is optional for functions defined as expressions. Function expressions are sometimes defined and immediately invoked.
💡Key Conceptual Anchor:Array And Function
Question 19 of 38
★ FPSC
★ PPSC
★ FPSC
★ PPSC
Consider the following code snippet : var string2Num =parseInt (" 123xyz ") ; The result for the above code snippet would be :
Correct Answer: Option B — 123xyz
Detailed Academic Explanation:
The parseInt() function returns the first integer contained in the string or 0 if the string does not begin with an integer.
💡Key Conceptual Anchor:Array And Function
Question 20 of 38
★ FPSC
★ PPSC
★ FPSC
★ PPSC
If you have a function f and an object o, you can define a method named m of o with
Correct Answer: Option A — o.m=m.f
Detailed Academic Explanation:
A method is nothing more than a JavaScript function that is stored in a property of an object. If you have a function f and an object o, you can define a method named m of o with the following line: o.m = f;
💡Key Conceptual Anchor:Array And Function
Question 21 of 38
★ FPSC
★ PPSC
★ FPSC
★ PPSC
For the below mentioned code snippet: var o = new Object () ; The equivalent statement is:
Correct Answer: Option C — var o= new Object
Detailed Academic Explanation:
You can always omit a pair of empty parentheses in a constructor invocation.
💡Key Conceptual Anchor:Array And Function
Question 22 of 38
★ FPSC
★ PPSC
★ FPSC
★ PPSC
Consider the following code snippet : var c = counter () , d = counter () ; c . count () d . count () c . reset () c . count () d . count () The state stored in d is :
Correct Answer: Option A — 1
Detailed Academic Explanation:
The state stored in d is 1 because d was not reset.
💡Key Conceptual Anchor:Array And Function
Question 23 of 38
★ FPSC
★ PPSC
★ FPSC
★ PPSC
Consider the following code snippet : var c = counter () , d = counter () ; function constfuncs () { var funcs = [] ; for(var i = 0 ; i < 10 ; i ++ ) funcs [ i ] = function () { return i; } ; return funcs; } var funcs = constfuncs () ; funcs [ 5 ]() What does the last statement return ?
Correct Answer: Option C — 10
Detailed Academic Explanation:
The code above creates 10 closures, and stores them in an array. The closures are all defined within the same invocation of the function, so they share access to the variable i. When constfuncs() returns, the value of the variable i is 10, and all 10 closures share this value. Therefore, all the functions in the returned array of functions return the same value.
💡Key Conceptual Anchor:Array And Function
Question 24 of 38
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What kind of scoping does JavaScript use?
Correct Answer: Option B — Lexical
Detailed Academic Explanation:
Like most modern programming languages, JavaScript uses lexical scoping. This means that functions are executed using the variable scope that was in effect when they were defined, not the variable scope that is in effect when they are invoked.
💡Key Conceptual Anchor:Array And Function
Question 25 of 38
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What must be done in order to implement Lexical Scoping?
Correct Answer: Option C — Reference the current scope chain
Detailed Academic Explanation:
In order to implement lexical scoping, the internal state of a JavaScript function object must include not only the code of the function but also a reference to the current scope chain.
💡Key Conceptual Anchor:Array And Function
Question 26 of 38
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What is a closure?
Correct Answer: Option C — Both Function objects and Scope where function’s variables are resolved
Detailed Academic Explanation:
A combination of a function object and a scope (a set of variable bindings) in which the function’s variables are resolved is called a closure.
💡Key Conceptual Anchor:Array And Function
Question 27 of 38
★ FPSC
★ PPSC
★ FPSC
★ PPSC
Which of the following are examples of closures?
Correct Answer: Option D — All of the mentioned
Detailed Academic Explanation:
Technically, all JavaScript functions are closures: they are objects, and they have a scope chain associated with them.
💡Key Conceptual Anchor:Array And Function
Question 28 of 38
★ FPSC
★ PPSC
★ FPSC
★ PPSC
Which of the following uses a lot of CPU cycles?
Correct Answer: Option C — Dynamically generated graphics
Detailed Academic Explanation:
Dynamically generating graphics from real-time data uses a lot of CPU cycles.
💡Key Conceptual Anchor:Array And Function
Question 29 of 38
★ FPSC
★ PPSC
★ FPSC
★ PPSC
Consider the following code snippet : var scope = "global scope" ; function checkscope () { var scope = "local scope" ; function f () { return scope; } return f; What is the function of the above code snippet?
Correct Answer: Option C — Returns the value in scope
Detailed Academic Explanation:
The above code snippet returns the value in scope.
💡Key Conceptual Anchor:Array And Function
Question 30 of 38
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What is the fundamental rule of lexical scoping?
Correct Answer: Option B — Functions are executed using scope chain
Detailed Academic Explanation:
The fundamental rule of lexical scoping is that the JavaScript functions are executed using the scope chain that was in effect when they were defined.
💡Key Conceptual Anchor:Array And Function
Question 31 of 38
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What is the opposite approach to the lexical scoping?
Correct Answer: Option C — Dynamic scoping
Detailed Academic Explanation:
The opposite approach to the lexical scoping is the dynamic scoping.
💡Key Conceptual Anchor:Array And Function
Question 32 of 38
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What is the purpose of the dynamic scoping?
Correct Answer: Option A — Variables can be declared outside the scope
Detailed Academic Explanation:
Dynamic scoping creates variables that can be called from outside the block of code in which they are defined. A variable declared in this fashion is sometimes called a public variable.
💡Key Conceptual Anchor:Array And Function
Question 33 of 38
★ FPSC
★ PPSC
★ FPSC
★ PPSC
Which of the algorithmic languages is lexical scoping standardized in?
Correct Answer: Option D — All of the mentioned
Detailed Academic Explanation:
Lexical scoping is standardized in all algorithmic languages (ALGOL), such as Ada, Pascal, and Modula2. Additionally, it is used in modern functional languages like ML and Haskel.
💡Key Conceptual Anchor:Array And Function
Question 34 of 38
★ FPSC
★ PPSC
★ FPSC
★ PPSC
Consider the following code snippet : if ( !a [ i ]) continue ; What is the observation made ?
Correct Answer: Option D — All of the mentioned
Detailed Academic Explanation:
All of the mentioned is the correct answer to “Consider the following code snippet : if ( !a [ i ]) continue ; What is the observation made”. This question is standard in competitive examination syllabi for Array And Function.
💡Key Conceptual Anchor:Array And Function
Question 35 of 38
★ FPSC
★ PPSC
★ FPSC
★ PPSC
Consider the following code snippet : var a = [ 1 , 2 , 3 , 4 , 5 ] ; a . slice ( 0 , 3 ) ; What is the possible output for the above code snippet ?
Correct Answer: Option A — Returns [1,2,3]
Detailed Academic Explanation:
Returns [1,2,3] is the correct answer to “Consider the following code snippet : var a = [ 1 , 2 , 3 , 4 , 5 ] ; a . slice ( 0 , 3 ) ; What is the possible output for the above code snippet”. This question is standard in competitive examination syllabi for Array And Function.
💡Key Conceptual Anchor:Array And Function
Question 36 of 38
★ FPSC
★ PPSC
★ FPSC
★ PPSC
The reduce and reduceRight methods follow a common operation called
Correct Answer: Option B — inject and fold
Detailed Academic Explanation:
inject and fold is the correct answer to “The reduce and reduceRight methods follow a common operation called”. This question is standard in competitive examination syllabi for Array And Function.
💡Key Conceptual Anchor:Array And Function
Question 37 of 38
★ FPSC
★ PPSC
★ FPSC
★ PPSC
Do functions in JavaScript necessarily return a value ?
Correct Answer: Option C — Few functions return values by default
Detailed Academic Explanation:
Few functions return values by default is the correct answer to “Do functions in JavaScript necessarily return a value”. This question is standard in competitive examination syllabi for Array And Function.
💡Key Conceptual Anchor:Array And Function
Question 38 of 38
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What is the difference between the two lines given below ? !!( obj1 && obj2 ) ; ( obj1 && obj2 ) ;
Correct Answer: Option D — The first line results in a real boolean value whereas the second line merely checks for the existence of the objects
Detailed Academic Explanation:
The first line results in a real boolean value whereas the second line merely checks for the existence of the objects is the correct answer to “What is the difference between the two lines given below ? !!( obj1 && obj2 ) ; ( obj1 && obj2 ) ;”. This question is standard in competitive examination syllabi for Array And Function.
💡Key Conceptual Anchor:Array And Function
✓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.