Skip to content
Advertisement

If statement considers FALSE promise as TRUE

I’m making authentication in my app. And have such code

JavaScript

changedPasswordAfter retuns promise (true or false) So I run request and get this into console.

JavaScript

As you see ttt is FALSE but IF statement decided that it is TRUE . How can I fix that ?

Advertisement

Answer

Because ttt (which is a very bad name for a variable) is a Promise not a boolean so the if statement return True because the variable ttt has reference (is not undefined or null). try to add await keyword. it will work but you have to make the function Async

JavaScript
User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement