Does javascript execution stop when an invalid line is encountered?

后端 未结 4 2180
孤独总比滥情好
孤独总比滥情好 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:30

    It does somewhat depend on what you're doing. Usually things will stop executing and, if you're using a smart browser with a console, an error message will be logged (and sometimes these error messages are helpful, even, but not always).

    UNCAUGHT EXCEPTION: SYNTAX ERROR, UNRECOGNIZED EXPRESSION: #

    enter image description here

    Sometimes, however, stuff will just silently fail with no error or warning, especially if you're using jQuery or another library. I've spent hours troubleshooting why something worked fine in WebKit and Firefox but silently failed in IE, and traced the culprit to a PEBCAK bug in a jQuery .append() method that was trying to insert some invalid HTML into the DOM. It was maddening because everything else worked fine, no errors, no warnings, nothing, but in IE that one function just wouldn't "go."

提交回复
热议问题