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 The Structure of Functions - Part 1 of 3

Parameters in JavaScript

What exactly do Parameters do and how to they help in JS?

1 Answer

Lisa Nguyen
Lisa Nguyen
22,731 Points

Hi Dana, parameters allow you to pass in arguments to a function to carry out a specific task.

Let's say you want to create a calculator app and one of the features was finding the sum of two numbers, you'd have the following function with two parameters, a and b:

function add(a, b) { return a+b; }

You can then do add(4,8); to find the sum of 4+8. In this way, the parameters a and b act as references to the arguments you pass into the function i.e. a = 4 and b = 8. How does this help in JavaScript? You can reuse the function again and again with different values for a and b instead of writing out:

var a = 4; var b = 8; var sum = a+ b;

which helps when it comes to writing clean, readable code. Hope this helps!

Thanks Lisa! That was very helpful :)

Lisa Nguyen
Lisa Nguyen
22,731 Points

No problem! Glad to help :)