object comparison test
by chandings
HTML
<link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/bootstrap/3.3.1/css/bootstrap.min.css">
<script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.3.8/angular.min.js"></script>
<div class="container" ng-app="myApp" ng-controller="myController">
<h1>Java Script object null check</h1>
<h3>Result for nullData</h3>
<p>{{nullDataResult}}</p>
<h3>Result for undefinedData</h3>
<p>{{undefinedDataResult}}</p>
<h3>Result for emptyDataResult: {{emptyData}}</h3>
<p>{{emptyDataResult}}</p>
<h3>Result for Data:{{data}}</h3>
<p>{{dataResult}}</p>
</div>
JavaScript
var myApp = angular.module("myApp", []);
myApp.controller("myController", function($scope){
$scope.nullData = null;
$scope.emptyData = {};
$scope.data = {value:"Not Empty!"}
if($scope.nullData){
$scope.nullDataResult = "null was tested as true!";
}else{
$scope.nullDataResult = "null was tested as false!";
}
if($scope.emptyData){
$scope.emptyDataResult = "Empty was tested as true!";
}else{
$scope.emptyDataResult = "Empty was tested as false!";
}
if($scope.undefinedData){
$scope.undefinedDataResult = "undefined was tested as true!";
}else{
$scope.undefinedDataResult = "undefined was tested as false!";
}
if($scope.data){
$scope.dataResult = "object with value was tested as true!";
}else{
$scope.dataResult = "object with value was tested as false!";
}
});