Skip to content
loading...

re: There's no "else if" in JS VIEW POST

TOP OF THREAD FULL DISCUSSION
re: Legacy is legacy, there is no doubt (although COBOL was invented as a most imperative language ever.) I admit I exaggerated the percentage, though....

I'm intrigued by what you said about if-statements. I'm curious to know how you would write the following callback function.

someRequest(URL, (err, result) => {
    if (err) {
        console.log(err);
    } else console.log(result);
}

I'm still a novice so it's difficult for me to imagine doing some things without if-statements. I would appreciate it if you could show meπŸ˜…πŸ™‚.

You could use something like promises.

someRequest(URL)
.then(result => console.log(result))
.catch(err => console.log(err));

Ooh. That's right. Forgot promises could do thatπŸ˜…. Thanks 😊

code of conduct - report abuse