# Javascript: Question re functions

**URL:** <https://discourse.processing.org/t/javascript-question-re-functions/20478>\
**Category:** Beginners\
**Created:** [May 4, 2020, 9:49pm UTC](https://discourse.processing.org/t/javascript-question-re-functions/20478 "2020-05-04T21:49:34Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![femke.blanco](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/femke.blanco/32/3431_2.png) [@femke.blanco](https://discourse.processing.org/u/femke.blanco)\
**Post date:** [May 4, 2020, 9:49pm UTC](https://discourse.processing.org/t/javascript-question-re-functions/20478/1 "2020-05-04T21:49:35Z")

</div>

1 - I can reference a function by its name.

```auto
function funName () {
  //code
}
console.log (funName); // -> function funName () {//code}
console.log (typeof funName); // -> function

```

2 - I can assign a function to a variable and reference the function by the name of the variable.

```auto
var x = function funName () {
  //code
}
console.log (x); // -> function funName () {//code}
console.log (typeof x); // -> function

```

3 - If I assign a function to a variable, I can no longer reference the function by its name.

```auto
var x = function funName () {
  //code
}
console.log (funName); // -> ReferenceError: funName is not defined

```

Can someone explain why the latter is the case?

Thanks in advance.

---

<div class="post-metadata">

**Author:** ![GoToLoop](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/gotoloop/32/86_2.png) [@GoToLoop](https://discourse.processing.org/u/GoToLoop)\
**Post date:** [May 4, 2020, 10:03pm UTC](https://discourse.processing.org/t/javascript-question-re-functions/20478/2 "2020-05-04T22:03:42Z")

</div>

The keyword `function` can be used either as a declaration statement:

> **[function declaration](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/function)**
>
> The function declaration (function statement) defines a function with the specified parameters.

  
Or as a way to instantiate a function inside an expression:  

> **[Function expression](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/function)**
>
> The function keyword can be used to define a function inside an expression.

When used as the former, it automatically declares a variable as well.

However as the latter, b/c it’s an expression and not a statement, we still need to assign it to some variable/property, or pass it as an argument.
