Q: What does the Math.random() function return in JavaScript?
-
A
A random integer between 0 and 1
-
B
A random float between 0 and 1
-
C
A random float between -1 and 1
-
D
None of these
B
Answer:
B
Explanation:
The Math.random() function returns a random float between 0 and 1.
The Math.random() function returns a random float between 0 and 1 because this is the range of values that the function is designed to return.
The function uses a pseudo-random number generator to generate the random float, which means that the numbers it generates are not truly random, but they are good enough for most purposes.
The Math.random() function is often used to generate random numbers for things like games, simulations, and other applications where a truly random number is not required.
Related Topic:
Share Above MCQ