Function Declarations
Learn how to declare and call your first function using the function keyword.
Step 1 of 5
The anatomy of a function declaration
A function declaration has four parts: (1) the `function` keyword, which tells JavaScript you're creating a function; (2) the name, which is how you'll refer to it later; (3) parentheses `()` that will hold inputs (we'll cover those in the next lesson); and (4) curly braces `{}` containing the code that runs when the function is called. The code inside the curly braces is called the function body.
Think of it this way: Declaring a function is like writing a recipe card and filing it in a recipe box. You give it a name ('Chocolate Cake'), list the steps inside, and put it away. The recipe doesn't make itself — it just sits there, ready to be used when you decide to cook.
Web Standard
Function declarations are 'hoisted' in JavaScript — the engine moves them to the top of their scope before executing any code. This means you can call a function before the line where it's declared. We'll explore hoisting in depth in a later lesson.
Learn more on MDN
JAVASCRIPTREAD ONLY
CONSOLE
Click "Run" to execute your code...