Open In App

JQuery | type() method

Last Updated : 27 Apr, 2020
Comments
Improve
Suggest changes
Like Article
Like
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. html
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>JQuery | type() method</title> 
<script src="https://code.jquery.com/jquery-3.4.1.js"></script>
<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. html
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>JQuery | type() method</title> 
<script src="https://code.jquery.com/jquery-3.4.1.js"></script>
<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:

Next Article

Similar Reads