JavaScript fundamentals / 06

Declaring and calling functions

Compare function declarations and expressions, define parameters, and call a function with arguments.

On this page

What is a function?

A function is a group of statements designed to perform a particular task. When called, its statements execute in order. JavaScript programs use named functions, anonymous functions, nested functions, callbacks, load-event handlers, arrow functions, and immediately invoked function expressions.

The basic shape is:

function functionName(parameter1, parameter2) {
  // Statements to execute
}

Two ways to define a function

The two forms introduced here are a function declaration and a function expression.

A declaration has the familiar named-function form:

function functionName(parameter1, parameter2) {
  // Statements to execute
}

A function expression can assign an anonymous function to a variable:

const functionName = function(parameter1, parameter2) {
  // Statements to execute
}

Their differences become especially important when we discuss hoisting later. For now, recognize both forms. The placeholder names in these three syntax examples have been translated from Korean.

Calling a function

Once a function is defined, call it by writing its name followed by parentheses containing the arguments.

Open the original function-call example on CodePen.

Editorial correction: the original article said missing arguments always cause an error. In JavaScript, a missing argument ordinarily gives its parameter the value undefined unless a default applies. Whether that leads to an error depends on what the function does with it.

Next, we will learn about arrow functions.

Moved here from Tistory

I migrated this post from my Korean Tistory blog, I am Jason Lee, to this website and translated it into English. My writing and projects now live together in one place.

The original publication date, code examples, and screenshots are preserved. Editorial notes clarify known issues in the original material.

Original post on Tistory English edition · Aug 30, 2026
← Back to all articles