30 Days Of JavaScript

Day 5: Functions Part 1

Lesson 3: Input, No Return

Functions that take no input are pretty limiting. Let's expand our function to take an input so it can be a bit more personalized.

When we declare the function we put name in the ( ) to say "hey, this function takes an argument called name). You can then access/use that argument inside the function by it's name.

When we call the function, we put what we want to be passed into the function inside the ( ). We pass in a string "Coder" and that gets logged inside the function.

String Concatenation

I will cover this in more detail later, but we can "add" strings together with the + operation like this above. Pretty handy how the + operator knows to add numbers and join (concatenate) strings 😎

You can pass in a variable as well, of course.

This also highlights something important. What you call your argument when declaring the function (we chose name) doesn't mean you have to use that same variable name on the outside (see how we chose usersName?).

JavaScript function arguments are positional. Which will be important in a couple of lessons time.

In the meantime, let's get something back from our function.


Go Pro?

Upgrade to Pro for quizzes, tracked progress and a completion certificate for just $25 🚀

Want more developer tips, tricks and tools?
Then follow me:
FREE Coding Career Quick Start Guide 🚀
Discover the best way to learn to code, how to land a job and valuable resources to help your journey in this free 15 page value packed guide.
Looking to email me? You can get me on my first name at allthecode.co