Why Math.random() type is number and Math.random is function?

Vlad Ivanov

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?

Anish Goyal

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.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Math.random number of random bits

From Dev

Math.random number of random bits

From Dev

Type Casting Math.random?

From Dev

Why JavaScript Math.random() returns same number multiple times

From Dev

Why does Math.floor(Math.random()) function always return "0"?

From Java

Is 161803398 A 'Special' Number? Inside of Math.Random()

From Dev

Selecting a number randomly with math.random()

From Dev

how to make Math.random round to a number

From Dev

How to Print Random number in a Math Table?

From Dev

Selecting a number randomly with math.random()

From Dev

Math.round (), How to with a random number?

From Dev

Math.random() Generates same number

From Dev

Is it possible for Math.random() === Math.random()

From Dev

Why use Math.random(), and what it does

From Dev

javascript TypeError: Math.random is not a function on chrome

From Java

Is a function that calls Math.random() pure?

From Dev

math.random function in lua to position object

From Dev

math.random function with step option?

From Dev

Math.random() javascript function *undefined* on Chrome

From Dev

math.random function with step option?

From Dev

math.random function in lua to position object

From Dev

Math.Random in function always the same result

From Dev

Math.random/floor with a function and onclick?

From Dev

Javascript Math.random() not *that* random…?

From Dev

Math.Random is not so random

From Dev

Math.random not working

From Dev

Math & JavaScript | Random chances

From Dev

Arrays Random Multiplication Math

From Dev

Math.random Scenario