Intro to Basic JavaScript Functions
When you start learning functions, you will inevitably run into someone calling them “fun-ctions”. It’s corny, but they aren’t wrong! Functions are fun — but once the complexity increases, things can get confusing. That’s why its good to have a solid understanding of the basics.
What do We Need Functions For?
Functions let us do an action as many times as we want, to as many things as we want. Say you want to make sugar cookies. It will take you quite a long time to bake a batch if you are shaping each cookie individually, and also you will probably end up with some goofy looking and uneven ones. The function is the cookie cutter, allowing us to use the same shape to create countless cookies.
Lets Look at Some Examples:
Ok, enough with the metaphors, lets look at some code!
Get Inga Phlegar’s stories in your inbox
Join Medium for free to get updates from this writer.
So say you want to print out the things that you think are yummy.
console.log("cookies are yummy")
console.log("anchovies are yummy")
console.log("avocados are yummy")
console.log("grapes are yummy")
console.log("metaphors are yummy")You could totally do this — but what if you wanted to mention more foods? You would get tired and hungry really fast.
So here is how you could utilize a function to type all the phrases for you:
function yummy(food){
console.log(food + "are yummy")
}The function yummy will allow us to insert any food before the “are yummy” phrase.
How can I make my own function?
So, now you have a bit of an idea of what a function is. To get started with using them, you need to get familiar with syntax, and some key terms.
Check out my next article for more information!
To learn about fat arrow functions, click here.









