WorksheetsJavaScript Arrays
Total questions: 30
Worksheet time: 18mins
What is proper syntax for declaring a array in JavaScript?
var arrayName =[ ];
var arrayName[ ] ={ };
array arrayName ={ };
obj var arrayName =[ ];
Which definition below best describe an array?
An array is a function identifier that can hold more than one parameter.
An array is a beam of light.
An array is a special variable, which can hold more than one value at a time.
An array is a special function, which can hold more than one value at a time.
What is first index value of an array?
-1
0
1
undefine
The length() method for an array will return _____.
the number of elements in the array
the last index value of the array.
the length of the name of the array variable
the capacity of the array
The push() method append to the _______ of the array.
beginning
middle
end
none of the above
The pop() method removes the _______ element of the array.
beginning
middle
end
none of the above
The push() method adds a new element to the beginning of an array.
true
false
The push() method adds a new element to the end of an array
true
false
The shift() method removes the first array element and "shifts" all other elements to a lower index.
true
false
The unshift() method adds a new element to an array (at the beginning), and "unshifts" older elements.
true
false
The sort() method sorts in JavaScript will arrange an array alphabetically, and arrange numbers in ascending order.
true
false
The sort() method sorts in JavaScript will arrange an array alphabetically, but will not sort numbers in ascending or descending order.
true
false
What will be the output to the console for the following code?
["New York", "Texas", "New Mexico", "Arizona"]
["New York", "Texas", "New Mexico", "Arizona", "Washington"]
["Texas", "New Mexico", "Arizona", "Washington"]
["Arizona", "New Mexico", "New York", "Texas", "Washington"]
What will be the output to the console for the following code:
var colors =["Red", "Green", "Yellow", "Orange", "Blue"];
colors.splice(0,3, "Purple");
console.log(colors);
["Purple", "Green", "Yellow"]
["Purple", "Green", "Yellow", "Orange", "Blue"]
["Red", "Green", "Yellow", "Orange", "Blue"]
["Purple", "Orange", "Blue"]
What will be the output to the console for the following code:
var colors =["Red", "Green", "Yellow", "Orange", "Blue"];
colors.splice(1,0, "Purple");
console.log(colors);
[ "Orange", "Purple", "Green", "Yellow"]
["Green", "Purple", "Yellow", "Orange", "Blue"]
["Red", "Green", "Purple", "Yellow", "Orange", "Blue"]
["Red", "Purple", "Green", "Yellow", "Orange", "Blue"]
What will be the output to the console for the following code:
var colors =["Red","Green","Yellow","Orange","Blue"];
colors.reverse();
console.log(colors);
["Blue", "Green", "Orange", "Red", "Yellow"]
["Blue", "Orange", "Yellow", "Green", "Red"]
["Red", "Green", "Purple", "Yellow", "Orange", "Blue"]
["Red", "Purple", "Green", "Yellow", "Orange", "Blue"]
What will be the output to the console for the following code:
var colors =["Red","Green","Yellow","Orange","Blue","Amber"];
colors.sort();
console.log(colors);
["Red","Green","Yellow","Orange","Blue"]
["Amber", "Blue", "Green", "Orange", "Red", "Yellow"]
["Amber", "Blue", "Green", "Orange", "Red"]
["Red","Green","Yellow","Orange","Blue","Amber"]
What will be the output to the console for the following code:
var colors =["Red","Green","Yellow","Orange"];
colors.shift();
console.log(colors);
["Red","Green","Yellow"]
["Yellow","Orange"]
["Green", "Yellow", "Orange"]
["Red","Green","Yellow","Orange"]
What will be the output to the console for the following code:
var colors =["Red","Green","Yellow","Orange"];
console.log(colors.length);
5
3
4
2
What will be the output to the console for the following code:
var numbers =[100,125,137,16];
numbers.sort()
console.log(numbers);
[100, 125, 137, 16]
[16,100, 125, 137]
[16,100, 137, 8]
[8,16,100, 137]
The sort() method will produce incorrect result when sorting numbers, even if you make the number into a string.
true
false
The forEach() method calls a function once for each array element.
true
false
What will be the output to the console for the following code:
var numbers =["100","125","137","16"];
numbers.sort()
console.log(numbers);
["100", "125", "137", "16"]
["16", "100", "125", "137"]
["16", "100", "137", "8"]
["8", "16", "100", "137"]
What will be the output to the console for the following code:
var numbers =["100","125","137","16"];
numbers.pop()
console.log(numbers);
["100", "137", "16"]
["125","137","16"]
["100","125","137","16"]
["100", "125", "137"]
To display information to the screen and not to the console which command should you use?
console.log()
display.write()
document.write( )
print.screen()
Single or Double Quotations
What would be the output for the following code block?
var n =["Left Eye","Chilli","T-Boz"];
console.log(typeof n);
string
undefined
array
object
JavaScript was created by Brendan Eich in ____?
1895
1980
2017
1995
Which of the variables below is an array?
var names="array"
var names = array;
var names = [];
var names[];
