Skip to content

Instantly share code, notes, and snippets.

@uniquename
Last active July 25, 2017 10:54
Show Gist options
  • Save uniquename/c642a1adf04a4aab1ce7d07ae308b232 to your computer and use it in GitHub Desktop.
Save uniquename/c642a1adf04a4aab1ce7d07ae308b232 to your computer and use it in GitHub Desktop.
/**
* Functions
*
* Think of functions as reusabel code blocks.
* The code inside is something that you want to call often.
* And you can pass them a value.
*/
function renderComment(comment) {
// hey there, jQuery, could you render this comment for me?
}
/**
* Beside the input, there can also be an output value
*/
function doSomeCalculation(inputValue) {
var output = inputValue * 12;
return output;
}
var myResult = doSomeCalculation(3);
//console.log(myResult);
/**
* Passing multiple parameters to a function
*/
function createSalutation(name, lastname, gender) {
var salutation;
if (gender == 'f') {
salutation = 'Dear Mrs. ';
} else {
salutation = 'Dear Mr. ';
}
salutation += name + ' ' + lastname;
return salutation;
}
/**
* Local and global scope
*/
var globalVariable; // This variable exists outside and inside the function
function doSomething() {
var localVariable; // This variable exists only in the function
}
/**
* Self executing anonymous function
*/
(function (){
console.log('Hello World');
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment