Open In App

JQuery | type() method

Improve
Improve
Like Article
Like
Save
Share
Report

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.




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


Output:

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




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


Output:



Last Updated : 27 Apr, 2020
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads