Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript JavaScript Basics (Retired) Creating Reusable Code with Functions Variable Scope

Ming Jun Lim
Ming Jun Lim
10,060 Points

i'm a little bit confused

var num1 = Math.random(); var num2 = alert(Math.random());

console.log(num1); console.log(num2);

In the javascript console, I can see the num1 value. But the value for num2 is undefined... Does this mean that alert() function does not return anything but Math.random() function returns a value?

1 Answer

Stephan Olsen
Stephan Olsen
6,650 Points

Does this mean that alert() function does not return anything but Math.random() function returns a value?

Correct, alert() makes a popup in your browser with a message. For this reason you should not use when assigning a value to a variable. Math.random returns a floating point value between 0 and 1.