21
18

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Javascript でtry-catchは使ってはダメ

Posted at

##内容
ネストが深かったり、return面倒だったりtry-catchを使いたくなる時があるかもしれません。
ただし、高速なWebアプリケーションを作るなら絶対使わないようにしましょう。

##テストケース
http://jsperf.com/try-catch-vs-if-vs-inline-if

try-catch
try {
 a
}catch(e) {
 a = {};
}
delete a;
if
if (typeof a === "undefined") {
  a = {};
}
delete a;

##手元の結果
ifで処理したほうが30倍くらい速かったです。
インラインで書いてみましたがあまり変わりませんでした。

21
18
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
21
18

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?