Q
How can you add a new element to the end of a JavaScript array?

Answer & Solution

Answer: Option A
Solution:
The 'push' method in JavaScript is used to add a new element to the end of an array. Therefore, option A, 'colors.push('blue');', is correct for adding a new element ('blue') to the end of the array 'colors'. Option B, 'colors.add('blue');', is incorrect as there is no 'add' method for arrays in JavaScript. Options C and D are also incorrect ways of adding elements to an array.
Related Questions on Average

Which statement correctly declares a JavaScript array?

A). let colors = ['red', 'green'];

B). const colors = {'red', 'green'};

C). const colors = ['red', 'green'];

D). var colors = ('red', 'green');

How can you convert a string to a number in JavaScript?

A). parseInt('10')

B). parseFloat('10.5')

C). Number('10')

D). All of the above

Which statement correctly declares a JavaScript function?

A). function greet() {}

B). const greet = function() {}

C). const greet = () => {}

D). const greet = {}

How do you access the last element of a JavaScript array?

A). colors[colors.length - 1];

B). colors.last();

C). colors[-1];

D). colors.getLast();

What is the purpose of the 'continue' statement in a JavaScript loop?

A). To exit the loop

B). To skip the current iteration

C). To restart the loop

D). To execute the loop body again

Which method is used to remove the last element from a JavaScript array?

A). colors.pop();

B). colors.removeLast();

C). colors.splice(-1, 1);

D). colors.deleteLast();

Which operator is used for strict inequality in JavaScript?

A). !==

B). !=

C). <>

D). /=

Which statement correctly declares a JavaScript object?

A). let person = {name: 'John', age: 30};

B). const person = ('name' => 'John', 'age' => 30);

C). const person = ['name', 'John', 'age', 30];

D). var person = {name: 'John', age: 30};

How do you concatenate strings in JavaScript?

A). Using the + operator

B). Using the - operator

C). Using the * operator

D). Using the / operator

How can you prevent a JavaScript function from executing immediately?

A). Using async/await

B). Using the defer attribute in HTML script tag

C). Wrapping the function in parentheses

D). Using the setTimeout function