What Is a Function?
A function is a reusable block of code.
What Is a Function? is a free Javascript for Kids lesson on CoddyKit. This is lesson 1 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the Javascript for Kids learning path, and your progress syncs across the web and the CoddyKit app. The Javascript for Kids course includes 4 lessons in total.
A Magic Spell! 🪄
Imagine you are a wizard. 🧙 A function is like a magic spell you can use again and again!
You write the spell once, then say its name whenever you want it to happen. ✨
Why Spells Are Cool 😎
Pretend you want to say "Hello!" ten times.
Instead of typing it ten times, you put it in a spell. Then you just cast the spell! 🎉
A Spell That Says Hi 👋
Here is a tiny spell. It says hi when we use it. Press Run and watch! 🟢
function sayHi() {
console.log("Hi, friend!");
}
sayHi();The Two Parts 🧩
A spell has two parts:
- Making the spell (writing it down) 📝
- Using the spell (casting it!) 🪄
We made sayHi, then we used sayHi().
The Magic Word 🔑
The word function tells the computer: "A spell is coming!" 🐉
Then we give the spell a name, like sayHi. Names help us find our spell later.
Curly Braces Hold the Magic ✨
The { } curly braces are like a treasure chest. 🧰
Everything inside the chest is the magic that happens when we cast the spell!
function cheer() {
console.log("Hooray!");
console.log("You did it!");
}
cheer();Cast It Many Times! 🔁
The best part: you can cast a spell as many times as you want! 🎆
function bark() {
console.log("Woof woof!");
}
bark();
bark();
bark();Spells Save Time ⏱️
If you change the spell once, it changes everywhere you use it. So smart! 🧠
No need to fix the same thing over and over. Wizards are lazy in a good way! 😄
Naming Your Spell 🏷️
Pick fun names that say what the spell does, like danceParty or feedCat. 🐱
Good names make your magic easy to read!
function danceParty() {
console.log("Wiggle wiggle!");
}
danceParty();Empty Until You Cast 🫥
Writing a spell does nothing on its own. It just waits. 😴
Only when you cast it with () does the magic happen! 🌟
You Are a Code Wizard! 🧙♂️
You now know that a function is a reusable spell. Make it once, cast it lots! ✨
Soon you will make your very own spells!
Quick Check 🧠
Time for a fun question! 🎯
You Are a Star! ⭐
Awesome work! A function is a spell you write once and use lots. 🎉
Next, you will write your very first spell. Get ready! 🚀
Learn JavaScript with an AI tutor — free
Write and run real code in your browser, get instant help from a 24/7 AI tutor, and pick up where you left off on the web or in the app.
- Courses
- 35
- Lessons
- 140
Frequently Asked Questions
Is the “What Is a Function?” lesson free?
Yes — the full text of “What Is a Function?” is free to read here on the web. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the Javascript for Kids course, upgrade to CoddyKit PRO. The Javascript for Kids course includes 4 lessons in total.
What will I learn in “What Is a Function?”?
A function is a reusable block of code. You practise Javascript for Kids with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.
Do I need any experience to start Javascript for Kids?
No prior experience is required. Javascript for Kids on CoddyKit is structured for beginners through advanced learners, so you can start here or from the beginning and move at your own pace. This is lesson 1 of 4.
How long does the “What Is a Function?” lesson take?
Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.
Can I write and run code in this Javascript for Kids lesson?
Yes. Every Javascript for Kids lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.
All lessons in this course
- What Is a Function?
- Making Your First Function
- Giving Functions Information
- Getting Answers Back