Control flow is the flow in which a computer would execute a statment.
A Function is a block of code used to perform a specific task.
let newFunction = function(){
console.log("im in a function")
}
newFunction();
When we call a function, we are telling the computer that we need to execute the block of code.
Invokes can happen multiple ways
the ()operation calls the function
functions can be used as variable values. This means we dont have to declare a variable with the result of the function, we can just call on it directly.
let myName = getName(Donna);
let text = "Hi my name is " + myName + " :)";
//Instead we can use
let text = "Hi my name is " + getName(Donna) + " :)";
The parenthesis is used include parameters. We can have single parameters or multiple parameters. If we are using multiple parameters, it must be separated by commas.
we only add return if we want something out of a function.
can invoke function before declaration but cannot invoke a function expression until after
A local variable is declared inside a function and can only be access in a function.
const obj = {};
obj.x = 3;
console.log(obj.x); // Prints 3.
console.log(obj); // Prints { x: 3 }.
const key = "y";
obj[key] = 5;
console.log(obj[key]); // Prints 5.
console.log(obj); // Prints { x: 3, y: 5 }.
read working with objects
Extracting data from arrays or objects using sytax that mirrors the construct of the array or object literals
const foo = ["one", "two", "three"];
// without destructuring
const one = foo[0];
const two = foo[1];
const three = foo[2];
// with destructuring
const [one, two, three] = foo;