Open In App

AngularJS angular.isUndefined() Function

Improve
Improve
Improve
Like Article
Like
Save Article
Save
Share
Report issue
Report

The angular.isUndefined() function in AngularJS is used to determine the value inside isUndefined function is undefined or not. It returns true if the reference is undefined otherwise returns false. 

Syntax:

angular.isUndefined( value )

Parameter value:

  • value: It is used to reference the value to check whether the value is defined or undefined.

Return Value: It returns true if the value passed is undefined else returns false. 

Example 1: This example uses angular.isUndefined() function in AngularJS to determine the value inside the isUndefined function is undefined or not. 

HTML




<!DOCTYPE html>
<html>
  
<head>
    <title>angular.isUndefined() function</title>
    <script src=
"//ajax.googleapis.com/ajax/libs/angularjs/1.3.2/angular.min.js">
    </script>
</head>
  
<body ng-app="app" style="text-align:center">
    <h1 style="color:green">GeeksforGeeks</h1>
    <h2>angular.isUndefined()</h2>
  
    <div ng-controller="isDefinedController">
        <b>Date:</b> {{date}}<br><br>
        {{isUndefined}}
        <br><br><br>
        <b>Date1:</b> {{date1}}<br><br>
        {{isUndefined1}}
    </div>
  
    <script>
        var app = angular.module("app", []);
        app.controller('isDefinedController',
            ['$scope', function ($scope) {
                $scope.date = new Date;
                $scope.date1;
  
                $scope.isUndefined = angular.isUndefined($scope.date)
                    == true ? "$scope.date is Undefined."
                    : "$scope.date is not Undefined.";
  
                $scope.isUndefined1 = angular.isUndefined($scope.date1)
                    == true ? "$scope.date1 is Undefined."
                    : "$scope.date1 is not Undefined.";
            }]);
    </script>
</body>
  
</html>


Output:

 

Example 2:  This example uses angular.isUndefined() function in AngularJS by verifying the defined & undefined values.

HTML




<!DOCTYPE html>
<html>
  
<head>
      <title>angular.isUndefined() function</title>
    <script src=
    </script>
    <style>
        body {
            text-align: center;
            font-family: 'Times New Roman', Times, serif;
        }
  
        h1 {
            color: green;
        }
    </style>
</head>
  
<body ng-app="App">
    <h1>GeeksforGeeks</h1>
    <h3>angular.isUndefined() Function</h3>
    <div ng-controller="geek">
        First value is {{displayVal1}}<br>
        Second value is {{displayVal2}}<br><br>
        <input type="button" 
               ng-click="Check()" 
               value="Check Value">
    </div>
    <script>
        var App = angular.module("App", []);
        App.controller("geek", function ($scope) {
            var val1 = "GeeksforGeeks";
            var val2;
            $scope.displayVal1 = '';
            $scope.displayVal2 = '';
            $scope.Check = function () {
                angular.isUndefined(val1)? $scope.displayVal1 = 
                'does not exist': $scope.displayVal1 = 'Exist';
                angular.isUndefined(val2)? $scope.displayVal2 = 
                'does not exist' : $scope.displayVal2 = 'Exist';
            }
        });
    </script>
</body>
</html>


Output:

 



Last Updated : 08 Nov, 2022
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads