CSE 121B: JavaScript Language

Functions

Overview

Functions in JavaScript are common control structures in programming. They are blocks of code that can be called by name to perform a specific task. Functions can be called multiple times throughout a program. Functions can also be passed data to work with, and can return data back to the caller.

"Functions are one of the fundamental building blocks in JavaScript. A function in JavaScript is similar to a procedure—a set of statements that performs a task or calculates a value, but for a procedure to qualify as a function, it should take some input and return an output where there is some obvious relationship between the input and the output. To use a function, you must define it somewhere in the scope from which you wish to call it. - MDN web docs"

Prepare

Check Your Understanding

Given the following code snippet:

let firstName = 'Antonia';
let lastName = 'Francesca';

Additional Resources