O'Reilly logo

MooTools 1.3 Cookbook by Jay Larry G. Johnston

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Reporting the type of a variable

Objects and variables get confusing; save a few moments by making them report to us.

Getting ready

To test a battery of variables, one must instantiate a battery of variables.

// string variable, integer, array, object, null, undefined
var string_var = 'hello';
var integer_var = 1972;
var array_var = ['1','two',3];
var object_var = {one: '1', two: 'two', three: function() { alert(3); }}
var null_var;
//var oops_var; // commented out "on purpose"

How to do it...

Call a function that reports the type of each of our variables.

<h2>without moo:</h2>
<script type="text/javascript">
report_typeOf(0);
</script>
<h2><strong>with</strong> moo:</h2>
<script type="text/javascript">
report_typeOf(1);
</script>

How it works... ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required