NEW
Font size
WorksheetsUnderstanding Arrays and Loops in JavaScript
Total questions: 7
Worksheet time: 7mins
What is the index of the first element in an array in most programming languages?
1
0
-1
2
In JavaScript, which method is used to add an element to the end of an array?
add()
append()
push()
insert()
Consider the following JavaScript code: `var numbers = [1, 2, 3, 4]; console.log(numbers[4]);`. What will be the output?
4
3
undefined
Error
Which of the following statements correctly initializes an empty array in JavaScript?
`var myArray = {};`
`var myArray = [];`
`var myArray = new Object();`
`var myArray = new Array();`
What will be the result of the following JavaScript expression: `'5' == 5`?
true
false
undefined
Error
Given the array `var fruits = ['apple', 'banana', 'cherry'];`, write a JavaScript `for` loop to print each fruit in the array.
`for (var i = 0; i < fruits.length; i++) { console.log(fruits[i]); }`
`for (var i = 1; i <= fruits.length; i++) { console.log(fruits[i]); }`
`for (var i = 0; i <= fruits.length; i++) { console.log(fruits[i]); }`
`for (var i = 1; i < fruits.length; i++) { console.log(fruits[i]); }`
Which of the following operators is used to check strict equality in JavaScript?
==
===
!=
!==
