What is a JavaScript File?

Mackenzie Kieran
dev@red
Published in
7 min readJun 5, 2018

To answer this question, it’s helpful to know a little bit about how “files” became a thing and how files containing programming language syntax became the ultimate medium for controlling computer systems.

The word “file” derives from the Latin “filum” — a thread. Neat.
By the 1950s when a computer engineer (most computer users were also engineers at the time) referred to a file, they were most likely talking about a file of punched cards.

“Punched cards helped launch the transition from doing math with computers to processing data. Patterns of holes punched in cards can represent any information. Punched cards can preserve data too: just file them away!” — http://www.computerhistory.org/revolution/punched-cards/2

What exactly were these punched cards used for? The caption above should give you an idea: They were the encoded instructions and other information to be input to a Stored-Program Computer.

“This stack of 62,500 punched cards — 5 MB worth — held the control program for the giant SAGE military computer network. “— http://www.computerhistory.org/revolution/memory-storage/8/326

And yes, you had to input all of your cards in the correct order!

Punched cards and JavaScript files are not too different. Any modern source code file is merely a set of encoded instructions and other information, like strings of words, lists of data and so-on, that your Stored-Program Computer will use to do what you want it to do.

Since the age of punched cards, we’ve luckily made a few improvements. We don’t have to use paper cards any more. Instead, the computer itself allows us to create digital punched cards and store them on our hard drives.

Very clever, and certainly more forest-friendly.

Cards or Tape?

Paper tape patterns representing data, for programming. Not so fun. — https://i.pinimg.com/originals/8b/f2/f6/8bf2f6f8d3deae4bed465b32906e80a4.jpg

At the time, another popular way to feed instructions to a Stored-Program Computer was in the form of long tapes with punched holes, owing to Alan Turing’s original description of how a Stored-Program Computer computer could work.

If these punched tapes look familiar, you might have heard of a Jaquard Loom? Or maybe, an Abstract Turing Machine?

One reason punched cards were preferred was because they were easier to edit while designing a program. Remember, instructions needed to be entered in order.

If you had a bug in your instructions, you didn’t have to physically cut the offending section of tape out and replace it to fix your code. You could just swap out the bad card for a good one and commence winning.

A “file” of punched cards. Slow version and fast version, nice. — https://en.wikipedia.org/wiki/Computer_file#/media/File:PunchCardDecks.agr.jpg

From Punched Cards to Programming Languages

“The Ferranti Mk1 was among the world’s first commercially available general-purpose (i.e. programmable) computers ” It could also play music by issuing the ‘hoot’ command.— http://120years.net/ferranti-mark-1-computer-freddie-williams-tom-kilburn-united-kingdom-1951/

In the early days of programmable computers, each new system, like the MK1 above, were complex and difficult to use. Writing programs was a time-consuming process that involved punching thousands of holes in cards or tape and hoping everything would work out.

By the early 50s a hand-full of companies were producing general purpose programmable computers, mostly for the military, and programming these computers began to emerge as a general discipline.

I imagine researchers must have asked a question like: “If I spent 6 months writing a magic calculator for the MK1, why shouldn’t I be able to use this same program on IBM’s ENIAC?” At the time this was impossible.

IBM ENIAC programmers circa 1950s. Early programming involved both hardware configuration and data-entry.

FYI: The first computer programmers were women. For a long time the the software used by early computer systems was designed and input by women. See this History.com article for insight into what may have caused the profession to shift from female-dominated to male-dominated.

Each computer system had its own method of inputting and storing programs, and those systems were usually hardware based, and so not practical to reconfigure.

What was needed was a generalised way of writing programs; a universal set of symbols that could be translated (typically we’d say “compiled” instead of translated) to the specific set of inputs for a given system.

Since all computers applied — and still do — the same Turing Machine mechanics we’ve already mentioned, this was so doable!

In 1956 the world welcomed FORTRAN, short for “formula translation” — the first practical high-level “programming” language — developed by researchers at IBM, which answered the call for a general method for commanding all computers.

And that’s still how programming works today. Your JavaScript files are translated, by a special program called a compiler (sometimes, most of the time it’s “interpreted”, it depends…), into inputs that your laptop or PC hardware understand!

FYI: This is where we get the terms “machine Language” vs. “programming language”, although both are used to create computer programs.

Compilers are computer programs themselves. A separate compiler would need to be written for each type of machine, and you could use the FORTRAN language to write one program that runs on any machine where the FORTRAN compiler was available and go home early.

For your enjoyment, some FORTRAN code (The FORTRAN syntax is at the top-left of the card), stored on a punched card because there was no such thing as a hard drive. — https://upload.wikimedia.org/wikipedia/commons/5/58/FortranCardPROJ039.agr.jpg

But Wait, Where’s the JavaScript Compiler?

This is an xkcd comic.

Compiled programs are a revolutionary idea, sure. But there’s a small problem.

It takes time to compile (translate) a program from some universal language, into machine instructions.

Compilation was OK when designing programs was mostly done by researchers and scientists, but as computers became more useful as tools for conducting business (i.e. earning money), so did their designers seek to meet the demands of the capitalists and their incessant lust for speed and efficiency, one might imagine.

The obvious solution was, instead of compiling the whole program before feeding it into the computer, to compile the program line-by-line as the source code is being read. Done!

It took a while, but by the 1980s, commercially viable interpreter programs (interpreters) and their general languages began to show up on the programming scene.

Apple saw the benefit of interpreted languages early on.

Who’s Interpreting my JavaScript files?

UN translator / interpreter — I could have used a more recent image, but I’m sticking to a theme.

Interpreters are programs, just like compilers, and there are a few JavaScript interpreters out there. Programmers at Google wrote the one that gets the most press.

It’s part of a larger system of programs used to execute JavaScript called V8. The interpreter program developed by Google, which is part of the V8 system is called Ignition.

The V8 “engine” including the “just-in-time” interpreter/compiler are part of Google’s web browser, Chrome.

It works just like we described. It looks at JavaScript source code and translates that code into machine instructions “just-in-time”, instead of ahead of time, so we don’t have to wait for a compiler to run our JavaScript code.

The formal name for this process is called just-in-time compilation or JIT compilation.

In truth, it’s a little bit more complicated, but you’re curious and not afraid to explore new ideas at length. How do I know? You’re still reading this.

FYI: Most of the V8 code is open source. In 2009 a programmer named Ryan Dhal took the V8 program out of the chrome source code and embedded it in his own program and called the whole thing “Node”.

Node can be installed into your operating system, and this freed the JavaScript interpreter from the browser. Thanks to Ryan, we can run JavaScript on (almost) any computer operating system now, without having to install a web browser. Thanks for that!

So, What is a JavaScript File?

There are a few ways we could answer this question. A file is information physically encoded on your hard drive (or onto a punch card, if you’re into that). It’s a buffer of UTF-8 codes representing text to be displayed on your computer screen, managed by your operating system …etc.

But given the brief history of programming in our rear-view, what can we now say about the humble JavaScript file, knowing what we know about the systems that gave birth to the idea of a “file” in the first place?

Given what we know about computer programs, we can say that a JavaScript file is a program or a part of a program of instructions meant to be fed into a computer system in order to get the computer perform some task. The file contains an encoded “abstract” or “high-level” version of those instructions.

JavaScript syntax itself is a “language” that is meant to be a universal, platform-independent way of producing the actual machine instructions necessary to complete the task.

The syntax of the JavaScript language is interpreted by a compiler, just-in-time for the necessary instructions to be executed by the CPU of your computer. Fun!

Thanks for coming by dev@red and making it to the end of this post. Look out for more posts about the fascinating history of computing and the people who pioneered the development of the miraculous machines we call computers.

If you liked this post and want to keep learning about web and app development with RED Academy, be sure to follow us on Medium or check out our website.

--

--