Difference between setTimeout with and without quotes and parentheses

前端 未结 6 1246
甜味超标
甜味超标 2020-11-22 07:06

I am learning JavaScript and I have learned recently about JavaScript timing events. When I learned about setTimeout at W3Schools, I noticed a strange figure wh

6条回答
  •  花落未央
    2020-11-22 07:53

        ##If i want to wait for some response from server or any action we use setTimeOut.
    
        functionOne =function(){
        console.info("First");
    
        setTimeout(()=>{
        console.info("After timeOut 1");
        },5000);
        console.info("only setTimeOut() inside code waiting..");
        }
    
        functionTwo =function(){
        console.info("second");
        }
        functionOne();
        functionTwo();
    
    ## So here console.info("After timeOut 1"); will be executed after time elapsed.
    Output:
    ******************************************************************************* 
    First
    only setTimeOut() inside code waiting..
    second
    undefined
    After timeOut 1  // executed after time elapsed.
    

提交回复
热议问题