-
Notifications
You must be signed in to change notification settings - Fork 0
Open
Description
Functions
- Write function declarations and function expressions
- Differentiate
console.logandreturn - Define functions that take multiple arguments
- Understand the use of functions (i.e. what's the function of a
function?) - Define a function without arguments
- Define a function with arguments
- Return a value from a function
What Are Functions?
Function are just reusable bits of code. For example, see below (without current value).
function doSomething() {
console.log("Hello World");
console.log("How are you today?");
}And then when you recall it:
doSomething()
//
Hello World
How are you today?Here's an idea to fix a function within another:
function chorus(){
console.log("Whoa, we're half way there");
console.log("Whoa, livin' on a prayer");
console.log("Take my hand and we'll make it - I swear");
console.log("Whoa, livin' on a prayer");
}
function chorusx4(){
//print 4x4 lines of lyrics
chorus()
chorus()
chorus()
chorus()
}What Are Arguments?
Arguments are basically whatever input you place inside () of function.
Here's an example:
function DeclareAge(age) {
console.log("I am " + age + " years old.")
}
DeclareAge(18) // I am 18 years old.What's the return Keyword?
The first thing you need to know is that every function returns something. But if you don't specify what to return or ask the console for a function, then it's going to return "undefined."
You use return when you want to "capture" or remember the result of a function.
Once it returns, the functions has completed execution - in other words, the function is OVER.
Metadata
Metadata
Assignees
Labels
No labels