Day 22 - JS functions
by Nino · 13 things on Twos
- Reusing Code with Functions
- Websites and apps like an increase/decrease volume button regularly need to perform the same task over and over
- Instead of creating lots of different code, websites use **functions** to group related code and perform the task in one place
- To begin grouping related code, we start by coding the keyword `function`
- Next comes the function's name in camel case, like `greetUser`, followed by parentheses, `(` and `)`
- Braces `{` and `}`, mark out the code block that belongs to the function.
- The code we want to group together goes between the braces. This function groups two related `console.log()` statements.
- To run the code, we need to **call** the function. We do that by coding its name followed by parentheses, like `greetUser();`
- Creating Parameters
- For a start, we can use constants inside functions. Like creating const name = "Ron"; and using it in the display statement
- [unfinished]
- ---