James McGrath

Quick tips, in-depth guides, and thoughts on the future of the web

What Is a Function?

What Is a Function?

🧪 Concept:
A function is like a recipe. You write it once and then reuse it to get the same result — or tweak it to serve different ingredients.

In code, it might look like this:

function sayHello() {
console.log("Hello, world!");
}

You just:
▪ Declared a function named sayHello
▪ Told it to log a message when called

To use it, just call it:

sayHello();

🧰 Why It Matters:
Functions keep your code clean, reusable, and organized. Instead of repeating yourself, you define it once and use it whenever you need it.

🎉 Quick Challenge:
Write a function that says something about you! Like:

function aboutMe() {
console.log("I love coffee and coding!");
}

Call it and see the magic happen.

🧠 Fun Analogy:
A function is your own custom button. Press it, and something happens. It could make toast, launch fireworks, or just say hi — you choose.

📚 Further Reading:
MDN Docs – Functions
W3Schools – JavaScript Functions

Subscribe to my feed to follow along. I’ll keep the lessons short and sweet.

Ctrl + Alt + Learn – Day 1: What Is a Variable?

One response to “What Is a Function?”

  1. […] What Is a Function? […]

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.