Functions

Functions can get very complex in javascript, but this is just the beggining.

How to make simple funcitons

Functions are first declared with the function keyword, and a name is given to it. Parameters can also be added, to allow data input in functions.

function myFunction(){
console.log('hello world')
}
myFunction() //Will log Hello World to console whenever called.

Using parameters in functions

function myFunction(a) {
let addOne = a + 1
console.log(addOne)
} //Adds one to the number put in, and than logs that number to the console.
myFunction(10) //Returns 11
//
function adder(a,b) {
let final = a + b
console.log(final)
} //Adds two numbers, and than logs that number to the console.
adder(1,7) //Returns 8

Getting more advanced with functions

You can also save a function's value to a variable. You do this using the return keyword.

let myFunctionValue = function() {
let a = 1
return a
} //The value of the variable myFunctionValue is 1.