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 trialRaihan Khan
2,168 PointsWhat is the purpose of using Parameter?
I want to know the difference between using just Variable and Parameter. Why not just use Variable instead of a parameter. It is confusing to use parameter I want more clarification.
1 Answer
Steven Parker
231,261 PointsVariables are used anywhere in a program, but parameters are used specifically to pass information to a function. Using parameters with functions makes them easier to maintain, easier to re-use in other programs, and easier for other developers reading the code to understand what information the function requires and uses.
Raihan Khan
2,168 PointsRaihan Khan
2,168 PointsBut why not use a variable inside the function. I understand easier to maintain and easier to read code but still not clear about it.
Steven Parker
231,261 PointsSteven Parker
231,261 PointsIt is "safer" in a way, since the scope is limited to the function, and it is also more efficient.
For example, without using a parameter:
But if you do use a parameter: