LoginSignup
54
52

More than 5 years have passed since last update.

パフォーマンスの観点から。

typeof演算子

if (typeof foo === 'undefined') { /* ... */ }
  • とりあえずエラーにならない
  • firefoxで異様に遅い

global変数のundefined

if (foo === undefined) { /* ... */ }
  • 上書きされる可能性あり
  • 思ったより遅くない

local変数のundefined

(function(undef) {
  if (foo === undef) { /* ... */ }
})();
  • chromeだと異様に遅い
  • firefoxだと速い
  • 圧縮の恩恵を得られる

void 0

if (foo === void 0) { /* ... */ }
  • 大抵のブラウザで割と速度が安定している
  • IE10だとやけに速い

まとめ

まぁ、undefined判定自体そんなに重い処理じゃない気がしますが、Chrome Web StoreFirefox Market Place用のアプリを作るときに極限までチューニングしたいってときには有用かもしれません。

参考

54
52
1

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
54
52