Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

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?