Calling Functions

Calling a Function

inline

  • Calling a function means you are using the function (as opposed to defining a function which only tells us what the function can do)

  • To call a function you simply write function name followed by parentheses (don’t forget the parentheses!)

  • Now you can call this function as many times as you want

/**
define / declare a function named shout()
by itself this doesn't do anything, we must "Call" it
in order to use it
**/

function shout() {
  console.log("HELLO!")
}

/**
Calling the function named shout we call a function by writing the name
of the function followed by parentheses
**/

shout()

JS Bin on jsbin.com


Exercise:

  • Create a function named beAnnoying that logs 'yolo'. Next, use your knowledge of calling functions to ensure that 'yolo' is printed 3 times in the console

JS Bin on jsbin.com