What is a programming language?
A programming language is the set of rules that defines the way in which source code is written. Unlike natural languages, these rules are quite strict. Any smallest mistake can cause the code not to run, or cause it to run and but somehow not work as expected. For example, you cannot write const name;
in JavaScript. These rules don't just exist in literature and in the minds of the developers who write programs in this language. They are clearly stated in the specification, the document describing how the language is supposed to work.
Syntactically correct code is only half the battle. It can't be run directly by a computer as it's just text. A computer can only execute machine code (ones and zeros). There are two methods of converting source code into machine code. Compilation is the process of creating a ready-to-run program. Most of the programs we deal with as users were compiled by someone. For example, Windows uses the exe extension for compiled programs. Another method is interpretation. With interpretation, the source code is converted into machine code not before the program is run, but rather while it's being processed. This is why it is called interpretation.
JavaScript is an interpreted language, which means you need a program to run it: an interpreter. For example, the interpreter for JavaScript code running on a server is most often Node.js, and the interpreter for front-end JavaScript code is the browser. Other machines, such as embedded devices or cars, may have their own interpreters.
The reality, however, is a bit more complicated than that: the interpretation is done by an engine embedded in both Node.js and browsers.
// node runs an interpreter which takes the source code index.js,
// parses it,
// then executes the code line by line
node index.js
All programming languages are broadly classified into interpreted or compiled languages. Each has its own pros and cons, described in various articles. Here, however, we're focusing on JavaScript.
JavaScript was originally designed for the most popular browser of the time. The new language provided a way to add interactive features to web pages, even though it was at first limited to snowflakes and some visual effects. As time passed, developers got used to this language and increased their efforts to build logic involving JavaScript. One of the most famous turning points was the emergence of Gmail, which made the most of Ajax (making HTTP requests to the server). JavaScript played an ever-increasing role in the creation of websites, and all browsers were having to think about how to support it. For this purpose, almost every major browser manufacturer created its own interpreter.
As the technology world has evolved, JavaScript has expanded beyond the browser. First came the server-side implementation of Node.js, followed by its use in embedded systems. Even your fridge can be programmed with JavaScript now.
On the one hand, the abundance of different interpreters allowed JavaScript to reach far beyond a single browser, but on the other hand, it led to compatibility problems. The same code could behave differently in different places. As a solution, the ECMAScript standard was created. This is a large document describing the structure of the language and its behavior in all possible situations. It is useful both for language developers and ordinary programmers. If there's something you don't understand about the behavior of JavaScript, you can always find the answer in ECMAScript.
ECMAScript is constantly evolving. Each new standard describes more features of the language: some add new syntax, others add new built-in features to the standard library. For the most part, standards are backward compatible, i.e., code written according to ES3 will be executed by most interpreters. Unfortunately, it sometimes goes wrong. The code changes its behavior over time, usually towards having stricter rules.
It's important to understand the fact that having a feature in the standard does not automatically make it available in all interpreters. This is because the specification and interpreters are somewhat divorced from one another. Updates to the specification are usually followed on by interpreters, but it takes time. The reverse may be true as well: a new feature first appears in one of the interpreters and then, as it becomes popular, it enters the standard. If you run code written under a new standard on an interpreter that has not been updated for a long time, it will most likely crash upon encountering a syntax error.
There are sites (here and here) that show the availability of various features in different interpreters. Developers use them to find out whether it is safe to use new language features in their projects.
The Hexlet support team or other students will answer you.
A professional subscription will give you full access to all Hexlet courses, projects and lifetime access to the theory of lessons learned. You can cancel your subscription at any time.
Programming courses for beginners and experienced developers. Start training for free
Our graduates work in companies:
From zero to a developer. Refunds in case you won't get a job
Sign up or sign in
Ask questions if you want to discuss a theory or an exercise. Hexlet Support Team and experienced community members can help find answers and solve a problem.