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.