javascript - Why does if(asynchronous.get()) work and is it ok to use it this way -


when use like

if(asynchronous.get()){...} 

and ansynchronous.get() asynchronous function, wonder how ever work if statement isn't testing unless function returns value. somehow have in code , works can explain why works , if should change it.

edit: assumption function asynchronous wrong, answered now.

the if statement checks if expression evaluates truthy value. seems function returns promise, function object, truthy value.

the function executed, not able process result way , if statement never evaluated false.

you need wait function resolve value , check value:

asynchronous.get().then(val => {     if (val) {...} }) 

Comments

Popular posts from this blog

asynchronous - C# WinSCP .NET assembly: How to upload multiple files asynchronously -

aws api gateway - SerializationException in posting new Records via Dynamodb Proxy Service in API -

asp.net - Problems sending emails from forum -