# Why does typeof function(){} returns "function"?

**URL:** <https://forum.freecodecamp.org/t/why-does-typeof-function-returns-function/419032>\
**Category:** I Built This\
**Created:** [September 4, 2020, 11:00pm UTC](https://forum.freecodecamp.org/t/why-does-typeof-function-returns-function/419032 "2020-09-04T23:00:43Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![aeum3893](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/aeum3893/32/123492_2.png) [@aeum3893](https://forum.freecodecamp.org/u/aeum3893)\
**Post date:** [September 4, 2020, 11:00pm UTC](https://forum.freecodecamp.org/t/why-does-typeof-function-returns-function/419032/1 "2020-09-04T23:00:43Z")

</div>

Let’s try the following in your console:

```auto
typeof function(){}
// "function"

const test = typeof function(){};

typeof test
// "string"

```

what?!

---

<div class="post-metadata">

**Author:** ![DanCouper](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/dancouper/32/158608_2.png) [@DanCouper](https://forum.freecodecamp.org/u/DanCouper)\
**Post date:** [September 4, 2020, 11:05pm UTC](https://forum.freecodecamp.org/t/why-does-typeof-function-returns-function/419032/2 "2020-09-04T23:05:06Z")

</div>

The `typeof` operator returns a string saying what the type of something is.

A function is a function, that’s why it returns `"function"`.

A string is a string, which is why `typeof "function"` returns `"string"`.

---

<div class="post-metadata">

**Author:** ![skaparate](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/skaparate/32/125896_2.png) [@skaparate](https://forum.freecodecamp.org/u/skaparate)\
**Post date:** [September 4, 2020, 11:06pm UTC](https://forum.freecodecamp.org/t/why-does-typeof-function-returns-function/419032/3 "2020-09-04T23:06:02Z")

</div>

Hi!

Because it’s a function 😛.

The only _confusing_ part should be _why test is a string_, in which case it’s because you’re assigning the result of `typeof` to test, which returns a string, hence `test` is of type `string`.

If you expected `typeof test` to return `"function"`, then you should assign the variable `test` a reference to one instead of the result of `typeof`.

Does it help?

---

<div class="post-metadata">

**Author:** ![ILM](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/ilm/32/363239_2.png) [@ILM](https://forum.freecodecamp.org/u/ILM)\
**Post date:** [June 1, 2021, 1:12pm UTC](https://forum.freecodecamp.org/t/why-does-typeof-function-returns-function/419032/4 "2021-06-01T13:12:05Z")

</div>

Closed on June 1, 2021, 1:12pm UTC


