user2380371
user2380371

Reputation: 1

What's the difference between "typeof str" and "typeof(str)" in JavaScript?

What is the difference between these two statements?

if (typeof errorMessage !== undefined)
{}

and

if (typeof (errorMessage) !== undefined)
{}

Upvotes: 0

Views: 176

Answers (1)

Quentin
Quentin

Reputation: 943579

One of them has a pair of entirely superfluous parentheses.

The difference between typeof foo and typeof (foo) is the same as the difference between 1 + 1 and (1) + (1).


An an aside, the typeof operator will give you a string, so you should be comparing to "undefined" not undefined.

Upvotes: 10

Related Questions