I have this value which I obtained from the fetch request which is outside my calling function scope. How can i compare this against a a value.
let h=isCodeExists(userInput).then(res => console.log(res));
I want to check if this value ==2
I have this value which I obtained from the fetch request which is outside my calling function scope. How can i compare this against a a value.
let h=isCodeExists(userInput).then(res => console.log(res));
I want to check if this value ==2
 
    
    As the response will only come later, you need to make the comparison also later, i.e. it should be done in the then callback:
isCodeExists(userInput).then(res => {
    console.log(res);
    if (res == 2) console.log("it is 2!!");
    // Any other logic that needs the value of `res` should come here...
});
