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 trialAndrew Alvarez
7,286 PointsIs the variable "randomNumber" inside of the method function necessary?
Can't we just return the random number instead of making that extra step?
1 Answer
andren
28,558 PointsYou are correct. Returning the value stored in the variable directly would have had the exact same effect.
The main arguable benefit to the technique shown in the video is that it can make the code slightly more readable, since you can look at the variable name and get a quick idea of what type of value it stores.
I personally don't tend to create a variable unless I need to reference the value multiple places, but some people do create variables entirely to make the code slightly more clear, like was shown in this video.
Andrew Alvarez
7,286 PointsAndrew Alvarez
7,286 PointsThanks a lot man!