Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why do most JavaScript frameworks use such short variable names?

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 common practice? It seems like it would harm maintainability.

like image 867
Alvar Avatar asked Jul 25 '26 22:07

Alvar


2 Answers

Its 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.

like image 168
Louis Avatar answered Jul 28 '26 12:07

Louis


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.

like image 41
Lucas Avatar answered Jul 28 '26 11:07

Lucas



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!