Declaring Functions

Declaring a Function

inline

  • A function declaration is code that stipulates what the function can do

  • Use the function keyword to define a function

  • Functions can be given a name

  • The name must be followed by parentheses

  • The opening and closing curly braces indicate a “code block”

  • The statements for your function goes within the code block

  • Also referred to as “defining a function”

Simply declaring the function will not run this code, this function must be called in order for the code inside the function to be run


Example

// declare a function named sayGoodMorning()
function sayGoodMorning() {
  console.log("Good Morning")
}

JS Bin on jsbin.com


Exercise

  • Declare a function named bark that prints (via console.log()) 'Woof, Woof'

JS Bin on jsbin.com