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

Answer & Solution

Answer: Option D
Solution:
All of the options (A, B, and can be used to convert a string to a number in JavaScript: - parseInt('10') converts a string to an integer. - parseFloat('10.5') converts a string to a floating-point number. - Number('10') converts a string to a number. Therefore, option D, 'All of the above,' is correct for converting a string to a number in JavaScript.
Related Questions on Average

Which statement correctly declares a JavaScript function?

A). function greet() {}

B). const greet = function() {}

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

D). const greet = {}

How can you comment a single line of code in JavaScript?

A). // This is a comment

B). <!-- This is a comment -->

C). /* This is a comment */

D). ''' This is a comment '''

What is the purpose of the 'this' keyword in JavaScript?

A). To refer to the current HTML element

B). To refer to the current JavaScript file

C). To refer to the current object

D). To refer to the current function

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 add a new element to the end of a JavaScript array?

A). colors.push('blue');

B). colors.add('blue');

C). colors.insert('blue', colors.length);

D). colors[colors.length] = 'blue';

What is the purpose of the 'break' statement in a JavaScript switch case?

A). To continue to the next case

B). To exit the switch statement

C). To restart the switch statement

D). To execute the default case

Which operator is used for strict inequality in JavaScript?

A). !==

B). !=

C). <>

D). /=

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();

What does the '===' operator check in JavaScript?

A). Type and value equality

B). Type equality only

C). Value equality only

D). Reference equality

Which statement correctly declares a JavaScript arrow function?

A). const add = (a, => a + b;

B). function add(a, { return a + b; }

C). const add = function(a, { return a + b; }

D). let add = function(a, { return a + b; };