Day 7 Recap of 30DaysofJavaScript
August 10, 2022 • 2 min read
Finished Day 7! Let's recap!
So, what did I learn on Day 7 of 30DaysofJavaScript? Let's see!
Day 7 was all about creating custom functions in JavaScript. Let's just jump right into it!
Click here to follow along.
Function
Functions are reusable blocks of code that will perform a certain task. The function can take a parameter, which then will be used in the arguement. Functions can store data by returning data types. Functions make code cleaner, reusuable, and easy to test.
Functions can be created in a few ways:
- Declaration function
- Expression function
- Anonymous function
- Arrow function
Function Declaration
Here is how to declare a function and then call it:
function functionName(){
// code for function
}
//Here is how to call a function:
functionName()
Functions call be made with and without a parameter:
function functionName(){
// code for function
}
//Here is how to call a function:
functionName()
function functionName(parameter){
// code for function
}
//Here is how to call a function:
functionName(parameter)
Functions can have more than 1 parameter, even an "unlimited" amount.
Anonymous Function
An anonymous functions is one without a name.
const anonymousFunction = function() {
// This will create an anonumous function in which the value will be stored in the variable anonumousFunction
}
Expression Function
Exprerssion Functions are Anonymous Functions that return a value.
const expressionFunction = function(n) {
return n + n
}
console.log(expressionFunction(5)) //10
Arrow Function
Arrow functions are an alternative way to write a function, as they use arrows instead of the function keyword to declare a function. Here's an example of both ways in action:
function add(n){
return n + n
}
const add = n => {
return n + n
}
Function w/Default Parameters
Functions can pass default values, in which if there is no arguement passed, the default value is used.
function funcName(param = value){
//code
}
funcName() //uses default value
funcName(arg) //arguement is passed
And this is the end of my recap of Day 7 of 30DaysofJavaScript. Phew, 1 week already?
Day 8 should be coming out soon! If you want to know when it comes out, subscribe to the blog below! Share if you found my content interesting, and consider buying me some boba with the link down below.
Until next time, wherever, and whenever you are, have an amazing day! Signing off.
If you liked this and would like to support, click the link below to send me a boba!!! 🧋