What you’ll learn
- What functions are and why they matter
- Declaring and calling functions
- Parameters and arguments
- Returning values (and why
returnisn'tconsole.log) - Default parameters
- Function expressions and arrow functions
- Functions that use other functions
- Habits for writing great functions
The pages
Eleven pages, about 16 minutes.
- What Is a Function? Let's say you've written some code that greets someone in a fancy way. Lovely. Now you need that fancy greeting in…
- Declaring and Calling a Function Here's how you make a function. Let's break it down. function is the keyword that says "I'm making a function."…
- Parameters and Arguments Our banner always says "Welcome, friend!" That's a bit impersonal. What if we want to welcome people by name? We need…
- Return Values So far our functions have printed things. But most of the time, you want a function to calculate something and give…
- Default Parameters Sometimes you want a parameter to have a sensible value if the caller doesn't provide one. You can give it a default…
- Function Expressions Here's a mind-bending idea: in JavaScript, a function is a value, just like a number or a string. That means you can…
- Arrow Functions In 2015, JavaScript introduced a shorter way to write function expressions, called arrow functions. They're called…
- Functions Working Together Functions really shine when you combine them. Big problems become a collection of small, easy problems, each solved by…
- Good Function Habits Writing a function is easy. Writing a good function takes a bit of practice. Here are the habits that will make your…
- Mini Project: The Converter Toolkit Let's build a little toolkit of useful conversion functions, and then use a loop to print a handy conversion table…
- Recap The key ideas of Grade 6, JavaScript functions, on one page. A function is a named, reusable block of code. Functions…
Reading is step one
CurlyScript turns these notes into a game: short questions, an explanation after every answer, and a test at the end of each grade. Free, with nothing to sign up for.