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... ...

Get MooTools 1.3 Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.