Question

How to identify kind of varible, I'm trying to compare in JavaScript? I just have always the same problems in JavaScript with the kind of varibles, like

  • int
  • String
  • boolean
  • float
  • object

so many times i have to use

  • Boolean(String) - to boolean variable
  • Number(String) - to int or float varible
  • String.toString() - to String variable

the problem is when I use to compare [(value==true)], when the variable is not boolean or when I try to compare with others values [(value==varible)]

so there is a way to know what kind of variable is? a way to know the type of value

Was it helpful?

Solution

User Himal say use typeof.. so I can found the answer

var myvar=5
alert(typeof myvar);
 //alerts "number"

so to know kind of varible use typeof

source : http://www.javascriptkit.com/javatutors/determinevar2.shtml

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top