Open In App

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:

Return Value: It returns the string.



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




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


Article Tags :