WDD 131: Dynamic Web Fundamentals

W03 Learning Activity: JavaScript Functions

Overview

Functions are fundamental building blocks in JavaScript. They are reusable blocks of code you can call by name to perform specific tasks. Functions can receive input data and return output 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

Prepare

Quick distinctions: Declarations are hoisted and named; function expressions assign a function to a variable; arrow functions are expressions with concise syntax and lexical this (no own this or arguments).

Check Your Understanding

Given the following code snippet:

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

Optional Resources