Functions
function addNums(numOne, numTwo) {
return numOne + numTwo;
}
console.log(addNums(2, 2));
Functions are chunks of functionality we declare for later use. Like in this example we have created an addNums() function, to take two numbers and return the sum of those numbers to us. numOne, and numTwo are parameters, meaning they are variables that will only exist inside the scope of the function, and they will assist us with the logic we need to perform. Since those variables are contained in the functions scope, when the function finishes it's execution, those variables are destroyed.
Objects
let santa'sList = {
name: 'Luka',
gender:'male',
age: 4,
naughty: no,
nice: yes,
}
In the simplest of terms, an object is a collection of properties. A property is a key to value relationship. Like name, and the string 'Luka'. The santa's list object has a property with a key of "name", that has the value of "Luka". of 'Quin'. Objects properties can have a value of any data type, even another object! Objects are very popular in holding together lots of varied, but related data, and they come with many built in methods for working with them. The MDN docs will have more information for you!
Conditionals
var weather = 75;
if(weather > 70){
console.log("Wear shorts today. It's going to be Hot!");
}
Hopefully, you've noticed the difference in an application when you are logged in versus when you are logged out. Most times, these values are based on certain conditions being true or false. Conditional statements, using boolean variables, are all over the place in applications.
Conditionals are used to check certain conditions in your application. Conditionals have the power to alter the state of your application based on certain conditions being met or unmet, true or untrue.
In this module, we'll look at if statements and how they are used with conditionals. We declare a variable and initialize it.
We use the if keyword to check a certain condition. Our condition checks if weather is greater than 70. If the value of weather is greater than, then we'll execute a console statement.