René Nyffenegger's collection of things on the web
René Nyffenegger on Oracle - Most wanted - Feedback -
 

typeof [JavaScript snippet]

function main() {

  var a = ['foo', 'bar', 'baz']
  var h = {one: 1, ten: 10, twenty_two: 22}

  var re1 = /foo/i;
  var re2 = new RegExp('foo', 'i');

  txt_out(typeof( a               )); // object
  txt_out(typeof( h               )); // object
  txt_out(typeof( main            )); // function
  txt_out(typeof( alert           )); // function
  txt_out(typeof("str"            )); // string
  txt_out(typeof(new String("str"))); // object
  txt_out(typeof( 42              )); // number
  txt_out(typeof( NaN             )); // number
  txt_out(typeof( Infinity        )); // number
  txt_out(typeof( null            )); // object
  txt_out(typeof(typeof(null)     )); // string
  txt_out(typeof(re1              )); // object
  txt_out(typeof(re2              )); // object

//txt_out(/xyz/                   )); // doesn't work
//txt_out(typeof( typeof          )); // doesn't work
}