Deck 10: Javascript: Arrays
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Unlock Deck
Sign up to unlock the cards in this deck!
Unlock Deck
Unlock Deck
1/18
Play
Full screen (f)
Deck 10: Javascript: Arrays
1
_________ are data structures consisting of related data items (sometimes called collections of data items).
A) lvalues
B) composites
C) arrays
D) variables
A) lvalues
B) composites
C) arrays
D) variables
C
2
What is the effect of the join statement in the following code
Var theArray1 = [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 ];
Var theArray2 = [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 ];
Var value = theArray1.join( " " );
A) The join method will concatenate the values of theArray2 to theArray1.
B) The join method will concatenate the values of theArray1 to theArray2.
C) The join method will create a string from the values in theArray1.
D) The join method will create a string with the values of theArray2 concatenated to the values of theArray1.
Var theArray1 = [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 ];
Var theArray2 = [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 ];
Var value = theArray1.join( " " );
A) The join method will concatenate the values of theArray2 to theArray1.
B) The join method will concatenate the values of theArray1 to theArray2.
C) The join method will create a string from the values in theArray1.
D) The join method will create a string with the values of theArray2 concatenated to the values of theArray1.
C
3
What does the following code do
For ( var col = 0; col < a[ 2 ].length; ++col )
A[ 2 ][ col ] = 0;
A) Sets the rows and columns to zero.
B) Sets the rows to zero.
C) Sets the columns to zero.
D) Sets all the elements in row 2 to zero.
For ( var col = 0; col < a[ 2 ].length; ++col )
A[ 2 ][ col ] = 0;
A) Sets the rows and columns to zero.
B) Sets the rows to zero.
C) Sets the columns to zero.
D) Sets all the elements in row 2 to zero.
D
4
Which of the following is an illegal array initialization statement
A) var n = [ 10, 20, 30, 40, 50 ];
B) var n = new Array( 10, 20, 30, 40, 50 );
C) var n[ 10, 20, 30, 40, 50 ];
D) var n = new Array( 5 ); for ( var i = 1; i < = 5; i++ )
N[ i ] = i * 10 ;
A) var n = [ 10, 20, 30, 40, 50 ];
B) var n = new Array( 10, 20, 30, 40, 50 );
C) var n[ 10, 20, 30, 40, 50 ];
D) var n = new Array( 5 ); for ( var i = 1; i < = 5; i++ )
N[ i ] = i * 10 ;
Unlock Deck
Unlock for access to all 18 flashcards in this deck.
Unlock Deck
k this deck
5
What will the browser display if the following script is executed
< script type = "text/javascript" >
< !--
Var theArray = [ 1, 2, 3, 4, 5, 6, 7, 8, 9 ];
ModifyArray( theArray[ 3 ] );
Document.write( theArray.join( " " ) );
Function modifyArray( i )
{
I = 11;
}
//-- >
< /script >
A) Nothing, the browser will generate an error.
B) 1 2 3 4 5 6 7 8 9
C) 1 2 11 4 5 6 7 8 9
D) 1 2 3 11 5 6 7 8 9
< script type = "text/javascript" >
< !--
Var theArray = [ 1, 2, 3, 4, 5, 6, 7, 8, 9 ];
ModifyArray( theArray[ 3 ] );
Document.write( theArray.join( " " ) );
Function modifyArray( i )
{
I = 11;
}
//-- >
< /script >
A) Nothing, the browser will generate an error.
B) 1 2 3 4 5 6 7 8 9
C) 1 2 11 4 5 6 7 8 9
D) 1 2 3 11 5 6 7 8 9
Unlock Deck
Unlock for access to all 18 flashcards in this deck.
Unlock Deck
k this deck
6
To refer to a particular location or element in the array, we spec ify the name of the array and the ________ of the particular element in the array.
A) contents
B) size
C) position number
D) type
A) contents
B) size
C) position number
D) type
Unlock Deck
Unlock for access to all 18 flashcards in this deck.
Unlock Deck
k this deck
7
Which of the following is the proper method to access the length of the array arr
A) arr[].length
B) arr[subscript].length
C) arr.length
D) arr(length)
A) arr[].length
B) arr[subscript].length
C) arr.length
D) arr(length)
Unlock Deck
Unlock for access to all 18 flashcards in this deck.
Unlock Deck
k this deck
8
In JavaScript, numbers and boolean values are passed to functions by ________.
A) value
B) parameters
C) memory
D) reference
A) value
B) parameters
C) memory
D) reference
Unlock Deck
Unlock for access to all 18 flashcards in this deck.
Unlock Deck
k this deck
9
What is the value of num assuming that all 12 elements of array test are initialized to 3
++test[ 7 ];
Var num = test[ 7 ];
A) 3
B) 4
C) 8
D) 10
++test[ 7 ];
Var num = test[ 7 ];
A) 3
B) 4
C) 8
D) 10
Unlock Deck
Unlock for access to all 18 flashcards in this deck.
Unlock Deck
k this deck
10
The first statement below ________ the array while the second statement ________ the array.
Var c;
C = new Array( 12 );
A) declares, initializes
B) initializes, declares
C) declares, allocates
D) allocates, declares
Var c;
C = new Array( 12 );
A) declares, initializes
B) initializes, declares
C) declares, allocates
D) allocates, declares
Unlock Deck
Unlock for access to all 18 flashcards in this deck.
Unlock Deck
k this deck
11
Pass-by- ________ is the method of passing the argument's address in memory to a function.
A) value
B) parameters
C) memory
D) reference
A) value
B) parameters
C) memory
D) reference
Unlock Deck
Unlock for access to all 18 flashcards in this deck.
Unlock Deck
k this deck
12
By default, the JavaScript sort method uses ________ to sort the array passed to it.
A) string comparison
B) binary search
C) linear search
D) bubble sort
A) string comparison
B) binary search
C) linear search
D) bubble sort
Unlock Deck
Unlock for access to all 18 flashcards in this deck.
Unlock Deck
k this deck
13
The sort method can be given a function to use for the comparisons it makes, called a(n) ________ function.
A) isLessThan
B) compare
C) compareTo
D) comparator
A) isLessThan
B) compare
C) compareTo
D) comparator
Unlock Deck
Unlock for access to all 18 flashcards in this deck.
Unlock Deck
k this deck
14
When working with data stored in arrays, it's often necessary to determine whether an array contains a value that matches a certain ________.
A) search value
B) value index
C) sub initializer
D) key value
A) search value
B) value index
C) sub initializer
D) key value
Unlock Deck
Unlock for access to all 18 flashcards in this deck.
Unlock Deck
k this deck
15
Pass-by- ________ is the method of passing a copy of the argument's value to a function.
A) value
B) parameters
C) memory
D) reference
A) value
B) parameters
C) memory
D) reference
Unlock Deck
Unlock for access to all 18 flashcards in this deck.
Unlock Deck
k this deck
16
What would the browser output if the following script is executed
< script type = "text/javascript" >
< !--
Var array = [ [ 1, 2, 3 ], [ 1, 2, 3 ] ];
For ( var i in array )
{
For ( var j in array[ i ] )
Document.write( array[ i ][ j ] + " " );
Document.writeln("< br / >");
}
//-- >
< /script >
A) Nothing, the script would generate an error
B) 1 2 3
C) 1 2 3 4 5 6
D) 1 2 3 1 2 3
< script type = "text/javascript" >
< !--
Var array = [ [ 1, 2, 3 ], [ 1, 2, 3 ] ];
For ( var i in array )
{
For ( var j in array[ i ] )
Document.write( array[ i ][ j ] + " " );
Document.writeln("< br / >");
}
//-- >
< /script >
A) Nothing, the script would generate an error
B) 1 2 3
C) 1 2 3 4 5 6
D) 1 2 3 1 2 3
Unlock Deck
Unlock for access to all 18 flashcards in this deck.
Unlock Deck
k this deck
17
Which of the following is the proper method to dynamically allocate memory to an array of 100 elements
A) var c = new c[ 100 ];
B) var c = new c( 100 );
C) var c = new Array[ 100 ];
D) var c = new Array( 100 );
A) var c = new c[ 100 ];
B) var c = new c( 100 );
C) var c = new Array[ 100 ];
D) var c = new Array( 100 );
Unlock Deck
Unlock for access to all 18 flashcards in this deck.
Unlock Deck
k this deck
18
In JavaScript, all objects and arrays are passed to functions by ________.
A) value
B) parameters
C) memory
D) reference
A) value
B) parameters
C) memory
D) reference
Unlock Deck
Unlock for access to all 18 flashcards in this deck.
Unlock Deck
k this deck