2

So I get how typeof can be an operator or a function. But when I do

console.log(typeof(typeof));

I got this message Uncaught SyntaxError: Unexpected token ')'

So what am i doing wrong here? What can i do to get the data type of typeof?

5
  • 8
    typeof is only an operator. Commented Sep 15, 2020 at 21:38
  • 2
    typeof(+) (or typeof +, since it is indeed an operator and therefore doesn't need parentheses) fails with the same error, which hopefully isn't a surprise. Despite it being all alphanumeric characters, typeof is an operator just like + and friends, so it behaves the same way. Commented Sep 15, 2020 at 21:46
  • 4
    I think this is a fine question. It bothers me that someone would downvote this and vote to close. Commented Sep 15, 2020 at 21:51
  • 2
    This is a common mistake made by beginners. Just because one can wrap parenthesis around an operand it does not turn the preceding operator into a function. Commented Sep 15, 2020 at 22:06
  • Removing all the content is considered vandalism. Please don't do this. Questions and answers at StackOverflow are not a free service for you exclusively but shall also help other visitors with similar problems. Commented Nov 26, 2021 at 7:35

1 Answer 1

2

typeof is an operator. (Source: MDN Web Docs: typeof.)

To sum up the documentation on operators, I'll say this: Every operator must work on an operand (or non-operator). A unary operator requires only one operand (i++, !j), a binary operator requires two operands (1+2, 'a' + 'b'), and there's even a special ternary operator. (Source: MDN Web Docs: Expressions and operators.) Or, if you like the original text...

A binary operator requires two operands, one before the operator and one after the operator...

A unary operator requires a single operand...

So, it's not possible to do...

  • + +
  • + ==
  • typeof +

Etc.. Naturally, then, typeof typeof will naturally not work, as it violates the rule about unary operators requiring operands.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.