Use of try-catch in JavaScript

前端 未结 4 456
隐瞒了意图╮
隐瞒了意图╮ 2021-02-05 15:26

How time-intensive is the use of try/catch in JavaScript? I have an application and I am using it in a function which is called a few hundred times. N

4条回答
  •  太阳男子
    2021-02-05 15:58

    The try/catch clause creates a new scope in javascript, so every variable that has to come from the parent scope will be slightly slower.

    The overhead isn't that great but too large to completely ignore for your inner loops.

    Take a look at this video for a more in-depth explanation: http://www.youtube.com/watch?v=mHtdZgou0qU

提交回复
热议问题