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

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

a) parseFloat()
b) parseInt()
c) Number()
d) All of the above

Answer:

d) All of the above

Explanation:

In JavaScript, you can convert a string to a number using parseFloat(), parseInt(), or Number(). Each has its specific use cases. parseInt() converts a string to an integer, parseFloat() converts it to a floating-point number, and Number() converts to either integer or float, depending on the input.

Reference:

JavaScript MCQ (Multiple-Choice Questions)

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top