Self, I wish you knew this... (about JS function parameters)

Advice to my younger self trying to understand JavaScript.

Self,

Early on in your journey very few things confused & aggravated you as much as JavaScript functions, particularly function parameters.

Above they're shown as parameterOne & parameterTwo. So...

  • What they are?

  • How do they work?

  • Were they invented to diminish any bit of hope you had to one day understand JS?

All questions you have asked, all questions we're not answering today. Instead...

I wish you understood them as 'placeholders' sooner.

Why it would have helped you

  • Saved you time - no more 'long division'-type thinking needed.

  • Better understand the code as a whole - seeing them as placeholders free up your (already limited) mental bandwidth to see the forest rather than just a few trees.

Let me explain

See parameterOne & parameterTwo as 'holding space' for what you want to 'pass' (as it's called...) into it. Then, whatever is done inside the function code to them (parameterOne & parameterTwo) is done to the thing you'll pass into it.

In this case parameterOne & parameterTwo becomes 1 & 2 & the code inside the function is the sum of the two parameters, i.e. 1 + 2 which gives you 3.

Hope this helps. I'll see you in the future.

Warmly,

You from the future