Determining variable type

M

mouseit

If I have a variable of some sort, say x, how can I find out what
variable type javascript thinks it is? For example, if I've declared x
as 5 earlier, how do I know now whether it's a string or a number,
isNaN returns false, regardless of whether I declared it as "5" or 5.
 
L

Lee

mouseit said:
If I have a variable of some sort, say x, how can I find out what
variable type javascript thinks it is? For example, if I've declared x
as 5 earlier, how do I know now whether it's a string or a number,
isNaN returns false, regardless of whether I declared it as "5" or 5.

Javascript doesn't think it needs to know.
Why do you think you do?


--
 
L

-Lost

mouseit said:
If I have a variable of some sort, say x, how can I find out what
variable type javascript thinks it is? For example, if I've declared x
as 5 earlier, how do I know now whether it's a string or a number,
isNaN returns false, regardless of whether I declared it as "5" or 5.

typeof or instanceof.

typeof will give the generic object type.
instanceof will only return true if it is an object of type [Object].
([Object] being any valid JavaScript Object; String, Function, Array,
Object, whatever.)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,904
Latest member
HealthyVisionsCBDPrice

Latest Threads

Top