Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

Sometimes you have a variable in Javascript and do not know whether it is a number or a string. You can test the type of a variable by using the typeof() operator like this:

     Var x     = 1.234;
Var y     = "Hello";
Var Type1 = typeof(x);
Var Type2 = typeof(y); 
 
Alert(Type1 + " and " + Type2);

...

 "undefined" is useful because it tells you that something does not exist yet (ie: it's undefined) so sometimes you see code like this:

     if (typeof(objGlobal.CustomerNumber) = "undefined")) objGlobal.CustomerNumber = "12345";