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 Treehouse Club - MASH MASH - JavaScript Stuff You Can Change

Paola Ledesma
Paola Ledesma
2,453 Points

Hi there! I was wondering if there is any reason why we need to add || 4 in the 3rd line of the .js doco. Thanks heaps!

var num = num || 4

2 Answers

simhub
simhub
26,543 Points

Hi Paola,

the || symbol means OR.

 var num = num || 4  // If no number passed in, default to 4

the "num" variable will first look for a "num" parameter to be set "function random_number(num){...}" if it isn't set then it will set the num variable "var num = ..." equal 4.

Because the computer will say - hey! you wrote "var num =..." that means you're declaring a variable name "num". Oh! and you want me too set it equal to "4" if there is no parameter "num" set in the "random_number(num)" function.

Paola Ledesma
Paola Ledesma
2,453 Points

simhub , thanks a lot! Does this mean that "4" is an arbitrary default value that could be changed?