1. Consider the code snippet given below
var count = [1,,3];
What is the observation made?
a) The omitted value takes “undefined”
b) This results in an error
c) This results in an exception
d) The omitted value takes an integer value
Explanation: Array is defined with a null value when no value is mentioned. If you omit a value from an array literal, the omitted element is given an undefined value.
2. Consider the following code snippet
var a1 = [,,,]; var a2 = new Array(3); 0 in a1 0 in a2
The result would be
a) true false
b) false true
c) true true
d) false true
Explanation: Array a1 is defined with null values. Therefore we can access the indexes 0,1 and 2.But array a2 is only defined not declared. Therefore we cannot access index 0.
3. The pop() method of the array does which of the following task ?
a) decrements the total length by 1
b) increments the total length by 1
c) prints the first element but no effect on the length
d) updates the element
Explanation: pop() function pops out that is delete the last element from the array. Hence pop() method (it works with push()) reduces the length of an array by 1.
4. Consider the following code snippet :
if (!a[i]) continue;
What is the observation made ?
a) Skips the undefined elements
b) Skips the non existent elements
c) Skips the null elements
d) All of the mentioned
Explanation: The if loop in the above code checks whether the value of a[i] exists or not. For undefined, non existent and null values the if loop returns true.
5. What will happen if reverse() and join() methods are used simultaneously?
a) Reverses and stores in the same array
b) Reverses and concatenates the elements of the array
d) Stores the elements of array in normal order
6. 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 ?
a) Returns [1,2,3].
b) Returns [4,5].
c) Returns [1,2,3,4].
d) Returns [1,2,3,4,5].
7. 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
d) Exception is thrown
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.
8. The primary purpose of the array map() function is that it
a) maps the elements of another array into itself
b) passes each element of the array and returns the necessary mapped elements
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
d) pass the elements of the array into another array
9. The reduce and reduceRight methods follow a common operation called
a) filter and fold
b) inject and fold
c) finger and fold
Explanation: The reduceRight() method reduces the array to a single value.The reduceRight() method executes a provided function for each value of the array (from right-to-left).The return value of the function is stored in an accumulator (result/total).Hence it does the operation of injecting and folding.
10. The method or operator used to identify the array is
Explanation: The typeof operator is used to get the data type (returns a string) of its operand. The operand can be either a literal or a data structure such as a variable, a function, or an object. The operator returns the data type.