angular.module('myReverseFilterApp', [])
.filter('reverse', function() {
return function(input, uppercase) {
input = input || ''; // declaring the variable
var out = '';
for (var i = 0; i < input.length; i++) {
out = input.charAt(i) + out;
}
// if condition for uppercase
if (uppercase) {
out = out.toUpperCase();
}
return out;//return statement
};
});
The code defines a filter for AngularJS that takes a string as input and returns the string in reverse order as well as uppercase.
I couldn't understand the code that is written in line number 4 that takes the input:
input = input || ''; // declaring the variable
It will be helpful if any one can describe me how line number 4 is taking input.