...

/

Introduction to Functions

Introduction to Functions

Learn one of the fundamental building blocks of all languages: functions. Learn how to write a function, why they're useful, and what we can do with them.

We'll cover the following...

We now get to one of the topics that new programmers find most difficult. Once the understanding sinks in, however, it’ll feel trivial. You’ll write functions pretty much every single day that you write code.

Let’s show some code and then discuss what’s happening.

Press + to interact
function myFirstFunction() {
console.log('Just ran my first function!');
}
myFirstFunction(); // -> Just ran my first function!

Creating a Function

To write a function, we start with the function keyword. We write the name we want to give the function after it. We write a pair of parentheses after that.

function functionName()

Function naming rules are the same as ...