Learning About JavaScript Functions
Tags: javascript, beginners
Published: 2023-05-17 20:29:59

## Introduction

Functions in JavaScript are the most interesting facet I have learned while coding, to date. Coding as a whole is astounding in that it has no limits, only possibilities.  Programming can be applied to any aspect of modern living, from medical applications to space travel, or as common as doing laundry. I am thankful to have been born in this era because I get to experience coding at such a vital time in history. Realizing that I have barely scraped the surface of coding leaves me motivated to dig deeper.

## About JavaScript Functions

Functions are a crucial part of JavaScript, they are versatile building blocks that are used consistently when communicating with JavaScript. Functions can be written in a few ways: Function declaration, function expression, and arrow functions. **Function declaration** is the *default* or *traditional* type of function and is the most similar to other languages.
```
function declarationStyle(parameter1, parameter2){
  console.log(parameter1, parameter2);
}
```
**Function expressions** can be constructed in multiple ways, one that includes a function name and one without.  A named function expression is a function assigned to a variable and works similarly to the standard *function declaration*.
```
const varName = function expressionStyle(parameter1, parameter2){
  console.log(parameter1, parameter2);
}
```
However, a **function expression** without a function name(an *anonymous* function) is often useful when you do not need to re-purpose or alter the function elsewhere, and just want to use the data returned by the function. An anonymous function expression could commonly be used as a parameter for another function.
```
const varName = function(parameter1, parameter2){
  console.log(parameter1, parameter2);
}
```
Finally, there are **arrow functions**. These are the most unique of the three, primarily because they can be written in many different ways.  One of which is formatted using a single line, unlike the previously mentioned functions.
```
parameter => console.log(parameter)
```
> *Note that parameters only need parentheses if there is more or less than one parameter, if there is only one parameter it may be written without parentheses like in the example above. This applies to all arrow functions.*

Also, similar to *function expressions* they can be written named or anonymous. Named **arrow functions** may look like this:
```
const varName = (parameter1, parameter2) => {
  console.log(parameter1, parameter2);
}
```
While anonymous **arrow functions** may look like this:
```
(parameter1, parameter2) => {
  console.log(parameter1, parameter2);
}
```

**Arrow functions** are used in many different situations similar to and vastly different from the examples above. I highly suggest reading [Mozilla's](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/Arrow_functions) for a more in-depth explanation of **arrow functions**(Or any of the function types) I have briefly mentioned above.

## Why I Love JavaScript Functions

JavaScript, out of the few languages that I have experienced so far, I've found to be the most interesting due to the broad yet streamlined application created by its functions. Functions are very similar to how I view decision-making. When met with a decision, I often think something like, "If I choose decision1 I will take x actions and if I choose decision2 I will take y actions."  Next, I can make a decision based on which one I believe will lead to the optimal outcome. To me, that sounds awfully similar to pseudocode:
```
function decisionsAreHard(decision1, decision2){
  if(decision1 > decision2){
    return decision1
  }else{
    return decision2
  }
}
```
Ever since I started learning about JavaScript my thought process has slowly altered in such a way that I try to turn as many of my actions into functions, like the one above, as I can. They may not always make sense but I find doing this oddly satisfying and genuinely helpful for remembering new expressions and syntax.

## Conclusion

Software Engineering is constantly growing and improving, as it always has and always will. Coding has come such an astonishingly long way in the short amount of time it has been around, making me so thankful to be a part of its growth. My outlook on programming throughout my learning experience has consistently evolved. However, one thought that never changed was how eager it has made me to pioneer in the software industry. Software engineering has rapidly become one of the many building blocks in the modern world and it still has such an untapped amount of potential that I can not wait to see how far it will go in my lifetime. I often feel as though I'm learning a deciphered alien language to improve our technological capabilities because I am constantly being impressed by all I am learning about software and what it can do. 

## Sources

I got my imformation from: [Mozilla](https://developer.mozilla.org/en-US/), [FlatIron School](https://flatironschool.com/welcome-to-flatiron-school/?utm_source=Google&utm_medium=ppc&utm_campaign=12728169839&utm_content=127574231184&utm_term=flatironschool&uqaid=513799628798&CjwKCAjw04yjBhApEiwAJcvNodna2NsIJBOQPPbZuI2uO8IHT1fyk_b5XSSfGbSXrcj2jx5XK5iVgBoCPcYQAvD_BwE&gclid=CjwKCAjw04yjBhApEiwAJcvNodna2NsIJBOQPPbZuI2uO8IHT1fyk_b5XSSfGbSXrcj2jx5XK5iVgBoCPcYQAvD_BwE)(Specifically the software engineering course I am attending), and [GeeksForGeeks](https://www.geeksforgeeks.org/).