Very long javascript question

Why some javascript code are extremely long(more than a million letters)? Is it really handwritten?

1 Like

There’s a lot of possibilities. Some javascript you see is the result of tens or even hundreds of people working on it over years, so that can easily add up to a lot of code.

Also, people have ways of dividing up code and sharing code that does common useful tasks, so that others can simply download it and include it. These ‘libraries’ of code can get used very often, and projects may bring in lots and lots of these libraries that they depend on to work. These are known as dependencies.

Finally, there can also be some parts of code that aren’t all written by hand, or are written by assistance. Code can be initially created faster using helper tools, or code that dynamically generates other code that is needed.

3 Likes

I would also add that if you are inspecting JS code from websites or web sources you may not be seeing the true source code. Many frameworks and projects transform the JS code before deploying to production in various ways. Some take code from different modules and libraries and create a single JS file that has everything. Others make the script file as small as possible by removing spaces or assigning very short names to variables.

Others transpile the code to an older version of JS for compatibility with browsers, making some things we do with a line of code now expand to many different lines or calls.

In any case, single files with thousands of lines of code are the complete opposite of what is expected when writing clean code that can be maintained. Breaking functionality into different modules and refactoring your functions as short and human readable as possible is the true goal to achieve.

Some legacy systems and projects that are not properly maintained and refactored may grow to become a scary bomb of code everyone is scared to work on.

1 Like