The Simplest Explanation of Functions You’ll Ever Read

Ebenezer Don
Apr 14 · 3 min read

Today, I will pick up You Don’t Know JS by Kyle Simpson from the shelf, open it and read a few chapters with understanding. Then, I will return it to the owner.

Tomorrow, I will pick up A Smarter Way to Learn JavaScript by Mark Myers from the shelf, open it and read a few chapters with understanding. Then, I will return it to the owner.

The day after tomorrow, I will pick up Eloquent Javascript by Marijn Haverbeke, open it and read a few chapters with understanding. Then, I will return it to the owner.

Three days from now, I will pick up…

You’re already wondering why I can’t just say “I will study Eloquent Javascript by Marijn Haverbeke” right?

Well, if you noticed, “study” to me involves a lot more than reading.

To make sure we’re on the same page, let’s define what it means to me:

Study:

Pick up book;

Open it;

Read with understanding;

Return to owner;

We just defined our first function.

Now that we know what “study” means, we can use it in our sentence:

“Today, I will study a book.”

“Tomorrow, I will study a book.”

“The day after tomorrow, I will study a book.”

One more problem though; our definition does not tell us which book I will study.

This is where “parameters” come in. We know I will study three different books in three days. We also know that the whole point of defining our function was so that instead of repeating the same long sentence, we can use a word or phrase. Each time we use this word, it would mean the exact same thing as our definition.

Since we don’t like the idea of writing three different definitions of “study” for the three days, we can involve parameters in this way:

Study (name_of_book, name_of_author):

Pick up name_of_book by name_of_author;

Open it;

Read with understanding;

Return to owner;

“name_of_book” and “name_of_author” are parameters we’ve defined along with our function, study.

With this, using the function “study” in a sentence would be as simple as:

“Today, I will study (‘You Don’t Know JS’, ‘Kyle Simpson’).”

This means the exact same thing as:

Today, I will —

Pick up You Don’t Know JS by Kyle Simpson;

Open it;

Read with understanding;

Return to owner;

We can even get adventurous and decide that we don’t want to return a book to the owner after we read it. We’d have to change one little thing in our function and add another parameter;

Study (name_of_book, name_of_author, destination):

Pick up name_of_book by name_of_author;

Open it;

Read with understanding;

Return to destination;

With our new function, we can decide to return today’s book to the owner, and tomorrow’s book to the shelf;

“Today, I will study (‘You Don’t Know JS’, ‘Kyle Simpson’, ‘owner’).

“Tomorrow, I will study (‘A Smarter Way to Learn JavaScript’, ‘Mark Myers’, ‘shelf’).

Really, that’s about it.

Well, definitely not all you’d need to know to be the next Master Shifu of Functions, however, you can now go into the world and read those “lofty high sounding explanations” of functions, written by real geniuses.

Here are a few resources that might be of help:

Computer Programming — Functions

JavaScript Functions — Understanding The Basics

Functions — The Modern JavaScript Tutorial

Functions — A Byte of Python

Do let me know if you found this helpful.

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade