Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
81
rated 0 times [  82] [ 1]  / answers: 1 / hits: 6326  / 10 Years ago, thu, april 10, 2014, 12:00:00

Just wondering, I'm writing test cases and haven't been able to find a definitive answer as to whether null can be returned in an angularJS promise (rather than an object called null )


More From » angularjs

 Answers
5

Yes, just like synchronous code a promise can fulfill with whatever you want it to.



//example with Bluebird
Promise.try(function(){
return null;
}).then(function(result){
alert(result === null); // true
});


A promise can also reject with null, but it generally shouldn't since you should always reject with errors.



In Angular, using $q the simplest example is something like $q.when(null) which creates a promise fulfilled with the value null explicitly.


[#46137] Wednesday, April 9, 2014, 10 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
mckinleyi

Total Points: 121
Total Questions: 100
Total Answers: 109

Location: Peru
Member since Fri, Oct 14, 2022
2 Years ago
;