Javascript TUTORIAL Quiz



Javascript Array Quiz # 1

The first Javascript Quiz covering Chapters 1 to 4 of the javascript Array Tutorial.


Q1. Which of the following JavaScript statements use arrays?

A . x = a(i)
B . x = a[i]
C . x = a >> i
D. x = a & i

Q2. Which of the following JavaScript statements is NOT a correct definitions of an array?

A . var a = new Array(100)
B . var a = new Array[100]
C . a = new Array(100)
D. a = new Array(1,2,3,4)

Q3. Which of the following JavaScript statements is a correct definitions of an array?

A . var a = new Array(100)
B . var a = new Array[100]
C . a = new Array[1,2,3,4]
D. var a = new Array[]

Q4. The JavaScript statement x = new Array(2,3)

A . defines a new two-dimensional array a whose dimensions are 2 and 3
B . defines an array a with two elements with a[1]=2 and a[2]=3;
C . defines an array a with two elements with a[0]=2 and a[1]=3
D. It is an incorrect way of defining an array

Q5. The JavaScript statement x = new Array[2,3]

A . defines a new two-dimensional array a whose dimensions are 2 and 3
B . defines an array a with two elements with a[1]=2 and a[2]=3;
C . defines an array a with two elements with a[0]=2 and a[1]=3
D. It is an incorrect way of defining an array

Q6. Consider the following JavaScript code:
    x = new Array();
    y = new Array();
    x[1] = 3;
    y[2] = 5;
    x = y;
	
Which values are contained in x[1] and x[2] after this code executes?


A . x[1] is 3 and x[2] is 5
B . x[1] is undefined and x[2] is 5
C . both x[1] and x[2] are undefined
D. This code will cause an error

Q7. Consider the following javascript code

   function myAdder(arr) {arr[1]++}
    a = new Array(1,3,2,5);

    myAdder(a);

document.writeln(a);

What is the output of the code.


A . 1,3,2,5
B . 1,4,2,5
C . The code has error
D. 2,3,2,5

Q8. onsider the following
var  a = new Array(12,false,"text");
x=10;
if (a[1]) x = 20;
else x = 30;
What is the value of x at the end of the execution


A . 10
B . 20
C . 30
D. The code has error

Q9. Which of the following array initializations is correct

A . var a = new array(12,false,"text");
B . a = new array(12,false,"text");
C . a = [12,false,"text"];
D. a = new [12,false,"text"];;

Q10. Consider the initialization of the two dimensional array
var iMax = 20;
var jMax = 10;
var f = new Array();

for (i=0;i<iMax;i++) {
 f[i]=new Array();
 for (j=0;j<jMax;j++) {
  f[i][j]=0;
 }
}
What is the value of f.length ?


A . 10
B . 20
C . 200
D. The code has error


Try other quizzes

Javascript Array Quiz 1

Javascript Array Quiz 2

Javascript Array Quiz 3