Defining Javascript Functions

Overview

What is a Function?

Function vernacular

// this is outside the scope of the of the function code-block
function myFunctionName() { // this is the function signature
    output_value = "Hello world"; // this is the beginning of the function code-block
    print(output_value);// this is the ending of the function code-block
}  // this is outside the scope of the of the function code-block

Function Parameters

// this is outside the scope of the of the function code-block
function myFunctionName(input_value) { // this is the function signature
    output_value = "Hello " + input_value; // this is the beginning of the function code-block
    print(output_value); // this is the ending of the function code-block
} // this is outside the scope of the of the function code-block

return

// this is outside the scope of the of the function code-block
function myFunctionName(input_value){ // this is the function signature
    output_value = "Hello " + input_value; // this is the beginning of the function code-block
    return output_value; // this is the ending of the function code-block
} // this is outside the scope of the of the function code-block

return vs print

sing a function

function greet(username) {
  let output = "Hello " + username
  console.log(output);
}


greet("Leon");
greet("Hunter");
Hello Leon
Hello Hunter