N
N
newaitix2022-04-21 17:07:54
JavaScript
newaitix, 2022-04-21 17:07:54

How to rewrite the code so that it can be used in a loop?

var onLinedsasd=(async()=>{
  if(navigator.onLine){
    var date=+new Date();
    var res=await fetch('/favicon.ico?_='+date);
    var ret=await res.headers.get('Content-Type').split('/')[0]=='image';
  }else{
    ret=navigator.onLine;
  }
  return ret;
});

I would like to rewrite such code xn, tu could be used in the loop condition. for example
if(onLinedsasd()){
//...
}else{
//...
}

Is it possible?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
W
wonderingpeanut, 2022-04-21
@wonderingpeanut

Because await is only valid inside async functions and in the global scope of a module (c) google translate

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question