I'm learning about Promise in Javascript. But when I tried to write some lines of code, I have this problem. My "if" statement, which I declare inside a Promise Obj always return true. Here's information:
- Environment: Chrome Dev Tools - Chrome Dev Tools - Chromium 64.0.3282.140
- Code:
var status = false;
var promise = new Promise(function(resolve, reject) {
if (status) {
console.log("TRUE")
resolve({
value: 'true'
});
} else {
console.log("FALSE");
reject({
value: 'false'
});
}
});
- Expected output: FALSE
- What happened instead: TRUE
- Notice: whatever the value of "status" is, the output always true.
I'm really looking for an explanation for my problem here. Thank you so much.