Let’s try the following in your console:
typeof function(){}
// "function"
const test = typeof function(){};
typeof test
// "string"
what?!
Let’s try the following in your console:
typeof function(){}
// "function"
const test = typeof function(){};
typeof test
// "string"
what?!
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"
.
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?