| title | theme | transition | highlightTheme | slideNumber | enableMenu | enableChalkboard | autoSlide |
|---|---|---|---|---|---|---|---|
Functions |
night |
slide |
dracula |
true |
false |
false |
0 |
This chapter should cover the following:
- Anatomy of functions
- Catagories of Functions
- Simple Example of Each function
- Links to subjections for detailed breakdown of each
A block of reusable code.
What a function declaration looks like:
function add(param1, param2){
return param1 + param2;
};
add(1, 2) //return a value of 3Has the following Features:
Block Syntax, with {} at the begining and the end of the function and usually followed by a ; {.fragment .current-only data-code-focus=1-3}
:::block
- Function keyword
- Name of function,
add - Parameters
(param1, param2), which act as variables inside the functions definition. {.fragment .current-only data-code-focus=1-1} :::
Return keyword, ends the function and the result is returned {.fragment .current-only data-code-focus=2-2}
:::block
-
Calling the Function
-
When the function is called, we pass values into the arguements
(1,2){.fragment .current-only data-code-focus=4-4} -
When the function is called, we pass values into the arguements
(1,2){.fragment .current-only data-code-focus=1-2}
function functionDeclaration(params) {
console.log(`hello ${params} \n`);
}
functionDeclaration("hello");
console.log(global) // not hoisted in node.js
// console.log(window.functionDeclaration("hello")) Remember function declarations is hoisted in the browser but not in node in{.fragment .current-only data-code-focus=5-6}
This errors out declarations is hoisted in the browser but not in node in{.fragment .current-only data-code-focus=5-5}