JQuery | type() method

This type() Method in jQuery is used to determine the internal JavaScript [[Class]] of an object.

Syntax:

jQuery.type( obj )

Parameters: The type() method accepts only one parameter that is mentioned above and described below:

  • obj: This parameter is the object to get the internal JavaScript [[Class]] of.

Return Value: It returns the string.

    Different obj return the following value for an object as a string.



  • jQuery.type( true ) === “boolean”
  • jQuery.type( new Boolean() ) === “boolean”
  • jQuery.type( 3 ) === “number”
  • jQuery.type( new Number(3) ) === “number”
  • jQuery.type( undefined ) === “undefined”
  • jQuery.type() === “undefined”
  • jQuery.type( window.notDefined ) === “undefined”
  • jQuery.type( null ) === “null”
  • jQuery.type( “test” ) === “string”
  • jQuery.type( new String(“test”) ) === “string”
  • jQuery.type( function(){} ) === “function”
  • jQuery.type( [] ) === “array”
  • jQuery.type( new Array() ) === “array”
  • jQuery.type( new Date() ) === “date”
  • jQuery.type( new Error() ) === “error”
  • jQuery.type( Symbol() ) === “symbol”
  • jQuery.type( Object(Symbol()) ) === “symbol”
  • jQuery.type( /test/ ) === “regexp”

Example 1: In this example, the type() method check whether the parameter is a array or not.

filter_none

edit
close

play_arrow

link
brightness_4
code

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>JQuery | type() method</title
<style>
    div {
        color: blue;
    }
</style>
</head>
<body style="text-align:center;"
      
    <h1 style="color: green"
        GeeksForGeeks 
    </h1
      
    <h3>JQuery | type() method</h3>
    <p> Check Whether the [] is array type:</p>
    <b></b>
    <script>
    $( "b" ).append( "" + jQuery.type( [] ) === "array");
    </script>
  
</body>
</html>                                    

chevron_right


Output:

Example 2: In this example, the type() method the object is undefined or null.

filter_none

edit
close

play_arrow

link
brightness_4
code

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>JQuery | type() method</title
<style>
    b {
        color: blue;
    }
</style>
</head>
<body style="text-align:center;"
      
    <h1 style="color: green"
        GeeksForGeeks 
    </h1
      
    <h3>JQuery | type() method</h3>
    <p> If Object is undefined or null, <br>Value return:</p>
    <b></b>
    <script>
    $( "b" ).append("undefined : " + jQuery.type( undefined )+ "<br>"+
    "window.notDefined  : " + jQuery.type(window.notDefined )+ "<br>"+
    "null  : " + jQuery.type( null  )+ "<br>"
    );
    </script>
  
</body>
</html>                                    

chevron_right


Output:




My Personal Notes arrow_drop_up

Small things always make you to think big

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.


Article Tags :

Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.