Function showMessage() {
 alert( 'Hello everyone!' );
  • Are the main "building blocks" of the program. They allow the code to be called many times without repetition.
  • The function keyword goes first, then goes the name of the function, then a list of parameters between the parentheses (empty in the example above) and finally the code of the function, also named "the function body", between curly braces.
  • A variable declared inside a function is only visible inside that function.
  • Can access an outer variable as well.
  • Has full access to the outer variable.
  • We can pass arbitrary data, using parameters (also called arguments).
  • If a parameter is not provided, then its value becomes undefined.
  • Can return a value back into the calling code as the result.

Functions — Structure map

Clickable & Draggable!

Functions — Related pages: