DEV Community

Discussion on: There's no "else if" in JS

 
napoleon039 profile image
Nihar Raote

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πŸ˜…πŸ™‚.

Thread Thread
 
kayis profile image
K

You could use something like promises.

someRequest(URL)
.then(result => console.log(result))
.catch(err => console.log(err));
Thread Thread
 
napoleon039 profile image
Nihar Raote

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