Array And Function(Computer Science > Javascript ) Questions and Answers

Question 1. Consider the code snippet given below
var count = [1,,3];
What is the observation made?
  1.    The omitted value takes “undefined”
  2.    This results in an error
  3.    This results in an exception
  4.    None of the mentioned
Explanation:-
Answer: Option A. -> The omitted value takes “undefined”

Question 2. Consider the following code snippet
var a1 = [,,,];
var a2 = new Array(3);
0 in a1
0 in a2
The result would be
  1.    true false
  2.    false true
  3.    true true
  4.    false true
Explanation:-
Answer: Option A. -> true false

Question 3. The pop() method of the array does which of the following task ?
  1.    decrements the total length by 1
  2.    increments the total length by 1
  3.    prints the first element but no effect on the length
  4.    None of the mentioned
Explanation:-
Answer: Option A. -> decrements the total length by 1

Question 4. What will happen if reverse() and join() methods are used simultaneously ?
  1.    Reverses and stores in the same array
  2.    Reverses and concatenates the elements of the array
  3.    Reverses
  4.    All of the mentioned
Explanation:-
Answer: Option A. -> Reverses and stores in the same array

Question 5. Consider the following code snippet :
if (!a[i]) continue ;
What is the observation made ?
  1.    Skips the undefined elements
  2.    Skips the non existent elements
  3.    Skips the null elements
  4.    All of the mentioned
Explanation:-
Answer: Option D. -> All of the mentioned

Question 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 ?
  1.    Returns [1,2,3]
  2.    Returns [4,5]
  3.    Returns [1,2,3,4]
  4.    Returns [1,2,3,4,5]
Explanation:-
Answer: Option A. -> Returns [1,2,3]

Question 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
  1.    1
  2.    [4,5]
  3.    [3,4,5]
  4.    Exception is thrown
Explanation:-
Answer: Option A. -> 1

Question 8. The primary purpose of the array map() function is that it
  1.    maps the elements of another array into itself
  2.    passes each element of the array and returns the necessary mapped elements
  3.    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
  4.    None of the mentioned
Explanation:-
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

Question 9. The method or operator used to identify the array is
  1.    isarrayType()
  2.    ==
  3.    ===
  4.    typeof
Explanation:-
Answer: Option D. -> typeof

Question 10. The reduce and reduceRight methods follow a common operation called
  1.    filter and fold
  2.    inject and fold
  3.    finger and fold
  4.    fold
Explanation:-
Answer: Option B. -> inject and fold