Section 3.3 — Functions
Learning JavaScript
Course: The Complete JavaScript Course 2025: From Zero to Expert! by Jonas Schmedtmann
Introduction
The fundamental building block of real world JavaScript applications are functions.
They are one of the most essential concepts in the language. So let’s study functions over the next couple of videos.
What are Functions?
Well in the most simple form, a function is simply a piece of code that we can reuse over and over again in our code.
So it’s a little bit like a variable but for whole chunks of code. Remember that a variable holds value, but a function can hold one or more complete lines of code.
So, let’s now declare our very first function. See example below:
function logger() {
console.log("My name is Dami");
}
logger();Let break certain things down:
1. The name of the function is logger and it was declared immediately after the keyword function. Just like variable naming's, we should always choose a descriptive function name so that we know exactly what they do.
2. logger(); This is the process of invoking the function (i.e running the function or calling the function).
Usually, when we write functions, we also pass data into a function and additionally, a function can also return data which we can now use for something else in the program.
I like to think of functions as machines. I think that’s a great analogy.
Get GlobalDami’s stories in your inbox
Join Medium for free to get updates from this writer.
For example, let’s imagine a food processor;
We put food into the processor then the processor does something to our food which is the function body basically and in the end, the food processor returns the processed food, e.g a juice. So this is exactly what we can do with functions as well.
Actually, let’s implement this example,
In this example, we can also specify something called parameters. Parameters are like variables that are specific only to this function and they will get defined once we call the function.
Here, we will give our fruit processor two parameters; apples and oranges.
Let’s dive into the code:
"use strict";
function fruitProcessor(apples, oranges) {
const juice = `Juice with ${apples} apples and ${oranges} oranges`;
return juice;
}
console.log(fruitProcessor(5, 0));As we had to return juice; in our function above, you have to understand that not all function needs to return a value and as well not all function needs a parameter.
And you need to understand that without you invoking, calling or running your function then the function is quite useless.
So, in conclusion to this lecture, we can say that functions allows us to write more maintainable code because with functions we can create reusable chunks of code instead of having to manually write the same code over and over again.
So those are the important things that we need to know about functions and if we understand these concepts then we would know when we should actually use functions.
And this is actually a very important principle for writing clean code that is used in programming all the time and this principle is called DRY (Don’t Repeat Yourself).
This is why functions are perfect for implementing dry code because they are reusable code blocks that together, make up all applications
And of course, we will use functions throughout the rest of the course and as we said in the beginning, they are like the fundamental building block of JavaScript programs.
And by now, we should understand that even console.log(); Number(); String(); are all functions — but they are built-in functions that we don’t have to write ourselves
It always gets better! 💪
Thank you for reading my blog post. Kindly follow me for more design and software development updates.
#JavaScript #LearningJavaScript #SectionIntro #Functions #Objects #Arrays #Loops #100DaysofCode #CodingJourney #LogicalDami










