On displaying to console.log command: typeof Math.random
it returns function
. But on command typeof Math.random()
result is number
. Why is it so?
That's because when you add the parenthesis, typeof is evaluating the type of the value returned by the function that is Math.random.
Math.random() returns a number, and typeof will be called using that returned number when the parenthesis are added.
In JavaScript, functions are objects, which is why you're able to use them like other variables.
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments