简体   繁体   中英

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.

I modified your jsfiddle

You were using bookPrice instead of this.price

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).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM