Skip to content

Functions

Marcelo Barsotti edited this page Jan 3, 2019 · 5 revisions

A sequence of computer program instructions to perform a specific task, packaged as a unit, is called a subroutine. In Javascript you create subroutines using functions. There are many reasons to write your code in functions. Among them:

  1. you can organize your code in smaller parts, that are easier to understand on their own;
  2. you can reuse the function over and over again and from multiple places (for example, console.log is a function you will use many, many times throughout this course);
  3. you can isolate parts of your code from others, making it harder to introduce unwanted errors.