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 trialUnsubscribed User
1,150 PointsCan someone explain me the underscore use, please??!
When he override the method of the "discountedPrice" in the parameters he used the underscore, but I didn't get it, please help me!
2 Answers
krilnon
1,458 PointsIt's a syntax for opting out of having to use a name for that parameter when calling the method.
So instead of having to write: tshirt.discountedPrice(percentage: 50)
, you can instead write tshirt.discountedPrice(50)
.
Adam Shockley
2,767 PointsBasically if you prefix the parameter name with an underscore it makes that parameter name optional. If a default value was set then the parameter in it's entirety is optional.
Aaron Creasey
1,707 PointsAaron Creasey
1,707 PointsAwesome thanks! That makes perfect sense
Adrian Topka
Courses Plus Student 2,205 PointsAdrian Topka
Courses Plus Student 2,205 PointsI explain myself so that it is the OPTIONAL char, whereby we could use function parameter but when we attribute some value to parameter then we doesn't must call parameter