Writing Custom Callback for ajax

In this post, I will share how could you use callbacks to write efficient and maintainable ajax using callbacks. Promises can also be use but here i will discuss it with callbacks.
The definition of callback is
A reference to executable code, or a piece of executable code, that is passed as an argument to other code. 
Let's see an example code of custom callback,
function test(param1, param2, callback) {
    alert('Started function.\n\nIt has: ' + param1 + ', ' + param2);
    callback();
}
test('foo', 'bar', function() {
    alert('Finished function.');
});

Check if object value exists and set new value for object key | Code optimization

Recently I have seen a code in the production that is
 if (!angular.isUndefined(newVal)) {
   if(!angular.isUndefined(newVal.min)){
     $scope.dataPoints.min = newVal.min;
   }
   if(!angular.isUndefined(newVal.max)){
     $scope.dataPoints.max = newVal.max;
   }
   if(!angular.isUndefined(newVal.yellowRangeMin)){
     $scope.dataPoints.yellowRangeMin = newVal.yellowRangeMin;
   }
   if(!angular.isUndefined(newVal.yellowRangeMax)){
     $scope.dataPoints.yellowRangeMax = newVal.yellowRangeMax;
   }
   if(!angular.isUndefined(newVal.redRangeMin)){

Pages