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

If you can write a function without a parameter, what is the point of adding them in?

I've seen many functions written without parameters at all, so I'm confused as to why they are necessary, or if they are. Are function parameters optional? Considered a best practice when used? Or what?

Thank you for your help.

1 Answer

Mark Buckingham
Mark Buckingham
5,574 Points

Hi,

I have seen this a lot in the tutorials and seems to be to avoid repetitive code, however I don't like it, it is bad practice to have functions referencing global variables and creates a testing and maintenance nightmare. I like to treat functions as a black box wherever possible and pass in whats needed and return any calculated result to the calling code.

Mark.