Does javascript execution stop when an invalid line is encountered?

后端 未结 4 2223
孤独总比滥情好
孤独总比滥情好 2021-02-07 05:33

If the browser is executing JavaScript on a web page and it encounters invalid JavaScript (e.g. somerandomthingy;) Does execution of JavaScript stop at that point, or do async o

4条回答
  •  無奈伤痛
    2021-02-07 06:22

    No code is executed past the error.

    function inAFunction(){
     alert("one");
     x = y;
     alert("two");  
    }
    inAFunction();
    

    you will see "one" but not "two"

    alert("one");
    x = y;
    alert("two");
    

    you will see "one" but not "two"

    var a = {
        b : c
    }
    alert("here");
    

    you will see nothing.

提交回复
热议问题