Web Designing MCQs

Top 20 Multiple-Choice Questions on JavaScript Arrays

Pinterest LinkedIn Tumblr
Here you will get collections of multiple-choice questions on JavaScript Arrays includes MCQ on adding and deleting array elements. It also includes different ways of iterating arrays for both dense and sparse arrays along with testing elements in order to execute null, undefined, and non-existent elements. MCQ on different array iteration methods and ECMAScript5 array methods in JavaScript also included here.

1. A …………………. array is one in which the elements not have contiguous indexes starting at 0.
A) special
B) sparse
C) heterogeneous
D) dense

2. If the array is ………………, the value of the length property is greater than  the number of elements.
A) special
B) sparse
C) heterogeneous
D) dense

3. The length property specifies the number of elements in the …………….. array in JavaScript.
A) special
B) sparse
C) heterogeneous
D) dense

4. If an array with five elements a=[1,2,3,4,5]; what will do the expression a.length=0
A) checks length of array is 0 or not
B) deletes all elements
C) replaces all elements with 0
D) adds 0 at the beginning

5. In ECMAScript 5, allows you to make the length property of an array read only with ………….
A) Object.defineProperty()
B) Object.readonlyProperty()
C) JavaScript.defineProperty()
D) JavaScript.readonlyProperty()

6. Which of the following is the correct expression to make length property of an array read only.
A) Object.defineProperty(a, “length”, {readonly:true});
B) Object.defineProperty(a, “length”, {writable:false});
C) Object.defineProperty(a, {length:writable});
D) Object.defineProperty(a, “length”, {readwrite:false});

7. Which of the following method can’t be used to add array elements in JavaScript.
A) push( )
B) shift( )
C) splice( )
D) All are can be used

8. Which of he following methods can be used to delete array elements in JavaScript array.
i) delete   ii) shift( )   iii) splice( )  iv) pop( )
A) i, ii and iii only
B) ii, iii and iv only
C) i, iii and iv only
D) All i, ii, iii and iv only

9. While iterating elements of an array a, …………………. will  test the array elements in order to skip null, undefined and non existent elements.
A) !a[i]
B) a[i]= = = undefined
C) !(i in a)
D) !a.hasOwnProperty(i)

10. While iterating the elements of an array a, what will do the following expression

for(var i=0; i<a.length; i++) {
if(a[i]= = = undefined) continue; // loop body
}

A) Skip null, undefined and non existent elements
B) Skip non existent elements
C) Skip undefined and non existent elements
D) Skip inherited properties


11. What the code should write in order to skip indexes for which no array elements exist but still want to handle existing undefined elements.

A)

for(var i=0; i<a.length; i++) {
if(!a[i]) continue; // loop body
}

B)

for(var i=0; i<a.length; i++) {
if(a[i]= = = undefined) continue; // loop body
}

C)

for(var i=0; i<a.length; i++) {
if(!(i in a)) continue; // loop body
}

D)

for(var i in a) {
if(!a.hasOwnproperty(i)) continue; // loop body
}

12. While iterating elements of an array a, ……………… will test the array elements in order to skip inherited properties.
A) !a[i]
B) a[i]= = = undefined
C) !(i in a)
D) !a.hasOwnProperty(i)

13. ……………… method in JavaScript converts all the elements of an array to strings and concatenates them to generate string.
A) Array.join( )
B) Array.concat( )
C) Array.slice( )
D) Array.splice( )

14. The ……………….. method in JavaScript returns sub-array of the specified array.
A) Array.join( )
B) Array.concat( )
C) Array.slice( )
D) Array.splice( )

15. The ………………. method in JavaScript is a general purpose method for inserting or removing elements from an array.
A) Array.join( )
B) Array.concat( )
C) Array.slice( )
D) Array.splice( )

16. Which of the following statements about JavaScript arrays are True.
i) setting length to a smaller value truncates the array.
ii) Arrays inherit useful methods from Array.prototype
iii) Array has a class attribute of “Array”.
A) i, ii and iii only
B) ii, iii and iv only
C) i, iii and iv only
D) All i, ii, iii and iv only

17. The …………… method is like the mathematical “for all” quantifier, which returns true if and only if the function returns true for all element in the array.
A) some( )
B) every( )
C) all( )
D) forall( )

18. State the following statements are True or False for JavaScript Array methods.
i) calling reduce( ) on an empty array with no initial value argument causes a TypeError.
ii) reduceRight() processes the array from lowest to highest
A) True, True
B) True, False
C) False, True
D) False, False

19. …………….. accept an optional argument specifies the this value on which the reduction function is to be invoked.
A) reduce( )
B) reduceRight( )
C) Both A and B
D) None of the above

20. In JavaScript array methods, ……………… does not provide a way to terminate iteration before all elements have been passed to the function.
A) for loop
B) for/in
C) forEach
D) every( )

Answers

1. B) sparse
2. B) sparse
3. D) dense
4. B) deletes all elements
5. A) Object.defineProperty()
6. B) ….(a, “length”, {writable:false});
7. B) shift( )
8. D) All i, ii, iii and iv only
9. A) !a[i]
10. C) Skip undefined and non existent elements
11. C) … if(!(i in a)) continue; …
12. D) !a.hasOwnProperty(i)
13. A) Array.join( )
14. C) Array.slice( )
15. D) Array.splice( )
16. D) All i, ii, iii and iv only
17. B) every( )
18. B) True, False
19. D) None of the above
20. C) forEach

Read Next:20+ Multiple Choice Questions On JavaScript Functions

Author

Shuseel Baral is a web programmer and the founder of InfoTechSite has over 8 years of experience in software development, internet, SEO, blogging and marketing digital products and services is passionate about exceeding your expectations.

Comments are closed.