jQuery.type()    **DEPRECATED in Version 3.3** JQ Home  <<  Utilities  <<  jQuery.type()

Object type detection.

Description

The jQuery.type() jQuery General utility method, returns a string representing the internal JavaScript [[Class]] of an object.

Shorthand version $.type()

  • Objects that are null or undefined return their respective values.
  • Objects that have an internal [[Class]] that equates to the users browsers built-in objects, return that value.

This method was deprecated in jQuery 3.3.

Syntax

Signature Description
jQuery.type( object )Return a string representing the internal JavaScript [[Class]] of an object.

Parameters

Parameter Description Type
objectThe object to retrieve the internal JavaScript [[Class]] for.PlainObject

Return

A String object.

jQuery.type( object ) Example Utilities  <<  Top

Return a string representing the internal JavaScript [[Class]] of an object.

In the example below when we press the button we create an array of objects and display their internal class.


$(function(){
  $('#btn4').one('click', function(){
    var arr1 = [obj0 = undefined, obj1 = null, obj2 = new Array(), obj3 = [], 
                obj4 = new Boolean(), obj5 = true, obj6 = new Date(), obj7 = new Function, 
                obj8 = function(){}, obj9 = new Number, obj10 = 3, obj11 = new Object, 
                obj12 = { a: 'b' }, obj13 = new RegExp, obj14 = (/regexp/), 
                obj15 = new String, obj16 = 'aaa'];

    for (var i=0; i<arr1.length; i++) {
      $('#div4').append('The Internal [[Class]] of obj' + i + ' is? ' +
                        $.type( arr1[i] ) + '<br>');
    }
  });
});

div4. Some initial text.

Press the button below to action the above code:

Related Tutorials

jQuery Intermediate Tutorials - Lesson 9 - jQuery General Utilities