William
William

Reputation: 4588

Javascript function return typeof number. But when typeof is omitted returns NaN

I have a function that when the return statement is prefaced with typeof it says it's a number. But when I remove it it outputs NaN.

I don't understand why.

Here's a fiddle:

http://jsfiddle.net/X3S56/

Thank you.

Upvotes: 1

Views: 162

Answers (2)

Anoop
Anoop

Reputation: 23208

I modified your jsfiddle

You were using bookPrice instead of this.price

Upvotes: 3

lanzz
lanzz

Reputation: 43168

Trying alert(typeof NaN) might be illuminating.

Although NaN literally means "not a number", it actually is a kind of number. Its meaning is "not a valid number" (in the sense of mathematical numbers), but it is still a number value (in the sense of Javascript types).

Upvotes: 2

Related Questions