> For the complete documentation index, see [llms.txt](https://raffycastlee.gitbook.io/marcyannotes/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://raffycastlee.gitbook.io/marcyannotes/codechallenge-curriculum/unit-0/20241001.md).

# CC-00: Functions and Console Logs

with Carmen Salas • 2024/10/01

[github](https://github.com/The-Marcy-Lab-School-Assignments/cc-00-console-return-raffycastlee)

***

## Code Challenge

1. In this code snippet, what is the **argument** and what is the **parameter**?

   ```jsx
   const sayHi = (name) => {
     return "Hi" + name
   };

   sayHi("fellows");

   ```

ans: `"fellows"` is the parameter `name` is the argument

***

2. What is the difference between `console.log` and the `return` statement? In your response, be sure to answer the following:
   1. What is the purpose of `console.log`?
   2. How is the `return` related to functions in JavaScript?

ans:

1. `console.log`'s main purpose is to essentially *see* an output into the console. In other programming languages, this is what `print` would be.
2. Every function has a corresponding `return`. It is implied to return `null` in occassions where it is not specified. `return` by itself acts to terminate a function, and *optionally* hold a value along with it.

***

3. What is printed to the console, when the function `sayHi` is *invoked*?

   ```jsx
   const sayHi = (name) => {
     console.log(name)
     return "Hi" + name;
   };

   sayHi("fellows");

   ```

ans: `fellows` is printed when the `sayHi` function is invoked. The `return` value however, is `"Hifellows"`.

***

4. Run this code in a file, what does the variable `hello` *evaluate* to? Why does it evaluate to this?

   ```jsx
   const hiFunc = () => {
     console.log("hi");
   };

   const hello = hiFunc();

   ```

ans: In the code above, `hello` evaluates into `"hi"`, as a `console.log` output. However `hello` as a variable remains `undefined`.

***

5. What is the difference between `let` and `const`? What is the best practice when choosing which keyword to declare a variable with?

ans: `let` and `const` are similar in the sense that they are both keywords used to *declare* variables. The key difference is that `let` allows variable re-definition/assignment while `const` does not.
