I have been told to use a meaningful variable name for years. However, every time I've tried to debug some JavaScript code and dig in to the third party framework, I found that every JavaScript framework would have variable names like a
, ac
, b
, c
.
Why are such short variable names mon practice? It seems like it would harm maintainability.
I have been told to use a meaningful variable name for years. However, every time I've tried to debug some JavaScript code and dig in to the third party framework, I found that every JavaScript framework would have variable names like a
, ac
, b
, c
.
Why are such short variable names mon practice? It seems like it would harm maintainability.
Share Improve this question edited Jul 30, 2013 at 4:21 icktoofay 129k23 gold badges259 silver badges237 bronze badges asked Jul 30, 2013 at 3:22 AlvarAlvar 5495 silver badges18 bronze badges 2- 1 Run your JavaScript through this tool and see what happens: jspress. – Marty Commented Jul 30, 2013 at 3:26
- 3 Why this downvoted a lot? Although minification is one of mon sense for JavaScript developers, but not for the others. – Mics Commented Jul 30, 2013 at 3:37
6 Answers
Reset to default 6Its called minification. Its done in all languages but mostly JavaScript to remove all unnecessary characters from source code. Its mostly JavaScript because large JavaScript files can be made much smaller thereby loading quicker in the browser.
Most JavaScript libraries have a version available for developers that is not minified so that debugging can be done and then in production the minified version is used to reduce the transfer overhead.
When writing code you should always use sensible variables, but that's only so the developer can read it, the browser doesn't care.
You are most likely looking at minified javascript. This is the result of passing the original (and hopefully more readable) source code through a minification tool.
What you're probably looking at is minimized code. Minimizers rewrite the Javascript to take the minimum amount of space, so it will download as quickly as possible -- unnecessary whitespace is removed, variables and functions are replaced with short names, and some other tricks are used.
It might be the javascript you're debugging is minified. There's no way to convert a minified javascript to original code with meaningful names written by the author. You just use your instinct and analyzing skills to understand others code even if the keywords there are unreadable.
What you are seeing could be a minified version of the actual javascript. it is done so that the size of the file is reduced for performance reasons.
A good example is the jQuery library, you can look at the development version and minified version
As the others have said, it's the minified version. My contribution to this thread is simply to show an example.
take this example:
(function () {
"use strict";
var foo = function () {
return;
};
var bar = foo;
var baz = bar;
})();
And run it through jspress.. The result will be
(function(){"use strict";var e=function(){return};var t=e;var n=t})()