Discussion: What’s the Value of Math?
Execute the code to understand the output and gain insights into assigning Math.random to the valueOf property.
Verifying the output
Now, it’s time to execute the code and observe the output.
Press + to interact
const r = {valueOf:Math.random},a = [r*11|0,r*11|0,r*11|0];console.log(a);
The valueOf
property
JavaScript has a handy property called valueOf
that automatically gets called when an object needs to be converted to a primitive value. By assigning Math.random
to the valueOf
property of an ...
Get hands-on with 1400+ tech skills courses.