Homelab, Linux, JS & ABAP (~˘▾˘)~

[JavaScript] Functions

/* Basic Function */
function reusableFunction() {
  console.log("Hello World");

/* Passing Values to Functions with Arguments */
function functionWithArgs(arg1, arg2 ) {
    console.log(arg1 + arg2);
functionWithArgs(1, 2); //returns 3

/* Global vs. Local Scope in Functions 
It is possible to have both local and global variables with the same name. 
When you do this, the local variable takes precedence over the global variable. */
var outerWear = "T-Shirt";
function myOutfit() {
  var outerWear = "sweater"
  return outerWear;
myOutfit(); //returns "sweater"

Leave a Reply

Your email address will not be published. Required fields are marked *