undefined vs local undefined var
JavaScript performance comparison
Test runner
Warning! For accurate results, please disable Firebug before running the tests. (Why?)
Java applet disabled.
| Test | Ops/sec | |
|---|---|---|
global undefined |
|
pending… |
local undefined var |
|
pending… |
Compare results of other browsers
Revisions
You can edit these tests or add even more tests to this page by appending /edit to the URL. Here’s a list of current revisions for this page:
- Revision 1: published
- Revision 2: published by @blixt
- Revision 3: published
3 comments
Note that this is mostly a size optimization, so closures can be minified better (variable renaming/shortening).
I love that the major of the test results are from iPhones.
Libs usually add
undefinedas an argument in their IIFE:This also avoids edge issues of
undefinedbeing overwritten in environments where it's writable.There's no common-use perf concern either. Note that even the slowest is still several millions of ops/sec on mobile/old-IE.
Minification is tricky and best left to minifiers. I've noticed several times, that adding variables in an attempt to reduce code size actually increased the gzipped size.
In my current project I run my code through several minifiers (and option combinations) to pick the smallest gzipped result (I automate this as part of the build process).