AngularJS – isUndefined() method

PythonServer Side ProgrammingProgramming

The isUndefined() method in AngularJS basically checks if a reference is defined or not. This method will return True if the reference passed inside the function is not defined or undefined, else it will return False.



Example − Check if the reference isUndefined or not

Create a file "isUndefined.html.3" in your Angular project directory and copy-paste the following code snippet.

<!DOCTYPE html>

      <script src= "">

   <body ng-app="app" style="text-align:center">
      <h1 style="color:green">
         Welcome to Tutorials Point
      <h2>AngularJS | angular.isUndefined()</h2>

      <div ng-controller="example">
         <b>Name: {{name}}</b>
         <b>Name: {{name2}}</b>

      <!-- Script for passing the values and checking... -->
         var app = angular.module("app", []);
         app.controller('example',['$scope', function ($scope)
            // Defining the keys & values
            $ = "SIMPLY LEARNING";

            $scope.isUndefined = angular.isUndefined($ == true
               ? "$ is Undefined."
               : "$ is Defined.";

            $scope.isUndefined1 = angular.isUndefined($scope.name2)== true
               ? "$scope.name2 is Undefined."
               : "$scope.name2 is Defined.";


To run the above code, just go to your file and run it as a normal HTML file. You will see the following output on the browser window.

In the code, $ is defined, whereas $scope.name2 is not undefined. Hence, we got this output.

Updated on 08-Oct-2021 10:48:32