how to replace undefined with a empty string how to replace undefined with a empty string angularjs angularjs

how to replace undefined with a empty string


As per this answer I believe what you want is

doc.text(50, 190, $scope.currentItem.JobOriginalBudget || " ")


undefined is a primitive value. Instead of comparing against the identifier undefined, you're comparing against the 9-character string "undefined".

Simply remove the quotes:

if ($scope.currentItem.JobOriginalBudget == undefined)

Or compare against the typeof result, which is a string:

if (typeof $scope.currentItem.JobOriginalBudget == "undefined")


simply remove the "== 'undefined'"

if (!$scope.currentItem.JobOriginalBudget) {    doc.text(50, 190, " ");}