You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
As seen in [the JavaScript 101 section](http://learn.jquery.com/javascript-101/testing-type/) the `typeof` operator can be inconsistent or confusing. So instead of using `typeof`, jQuery offers utility methods to help determine the type of a value.
110
+
111
+
First of all, you have methods to test if a specific value is of a specific type.
112
+
113
+
```
114
+
$.isArray([]); // true
115
+
$.isFunction(function() {}); // true
116
+
$.isNumeric(3.14); // true
117
+
```
118
+
119
+
Additionally, there is `$.type()` which checks for the internal class used to create a value. You can see the method as a better alternative for the `typeof` operator.
120
+
121
+
```
122
+
$.type( true ); // "boolean"
123
+
$.type( 3 ); // "number"
124
+
$.type( "test" ); // "string"
125
+
$.type( function() {} ); // "function"
126
+
127
+
$.type( new Boolean() ); // "boolean"
128
+
$.type( new Number(3) ); // "number"
129
+
$.type( new String('test') ); // "string"
130
+
$.type( new Function() ); // "function"
131
+
132
+
$.type( [] ); // "array"
133
+
$.type( null ); // "null"
134
+
$.type( /test/ ); // "regexp"
135
+
$.type( new Date() ); // "date"
136
+
```
137
+
138
+
As always, you can check the [API docs](http://api.jquery.com/jQuery.type/) for a more in-depth explanation.
0 commit comments