What Is JavaScript and How Does It Work?

What Is JavaScript and How Does It Work?

Today we are talking about JavaScript. JavaScript is the programming language at the heart of the modern web. The trick is that there is no such thing as JavaScript! What!

What crap is that again! Yeah! It’s gonna be a complicated article…

JavaScript was created in 1995 but very quickly, in 1997, it has been standardized at the standards organization ECMA International under the name ECMAScript. Ah… that’s why you said there is no such thing as JavaScript Ahem! Not really. It’s a little bit more subtle than that.

ECMAScript defines the basic syntax of the language and its core mechanisms but in itself it doesn’t do very much. I mean… Like any other programming language it needs a standard library to be truly usable And this is where things get complicated.

These days there are two flavors of JavaScript: On the one hand: JavaScript in the browser. In here you get a bunch utilities to: modify your HTML document making network requests managing data doing audio and graphics rendering and many, many… many more.

On the other hand: JavaScript on the server There you get a very different set of utilities that let you manage the computer directly, access files and folders, handle network resources, spawn processes, etc.

In each case, you have access to a very different range of functionality, that have… absolutly nothing in common… at all!

In many aspects, JavaScript on the server is closer to what other programming languages usually do. However, JavaScript in the browser is what people use the most on a daily basis so, for that very reason, this is what I’ll focus on for the rest of this article. So Let’s focus on JavaScript inside the browser.

Like CSS, JavaScript is embedded in HTML using a specific HTML element:

So, you can write down JavaScript code directly inside the element. Or you can write it in a dedicated file that you can link to in your HTML document. I’m not gonna teach you JavaScript today, but let’s walk through some silly code to see how it looks. As you can see, it’s a typical programming language.

We have:

function declarations and function calls, variable declarations, conditional tests, iteration loops, Web standards API calls, and even some fancy string templates.

Let’s stop on line 15. This line registers an event listener. In plain English! we define a function that will be called when the “load” event of the current window is emitted.

This is one of the key concepts behind JavaScript. Unlike many languages, JavaScript has native asynchronous mechanisms that let it react to events. In a nutshell some tasks can take a looooong time and complete later, in the future. Reading some data out of a database, getting geolocation data, making a network request… Or the user can interact with the page.

Clicking, touching, inputing text, scrolling, dragging… In cases like this, nobody wants to see their browser freezing until it is done. To avoid that, JavaScript delegates the work in the background, and when it is done an event is emitted. An event that your code can listen for and react to.

So, asynchronism is a very important feature of the language but by no means the only one. Object prototype, first class functions, internationalization, iteration, closure… Exploring JavaScript and the thousands of APIs available in the browser will take us on an amazing journey in the modern web.

Okay, let’s recap!

JavaScript is a programming language. It’s a combination of the ECMAScript standard with other standard functionalities. It’s highly asynchronous and it can react to events. And… no, sorry, it is not that simple!

JavaScript is maybe the most complicated technology of the whole web platform, but it’s also the most powerful. And you’ve been told: With great power comes great responsibility, you know the deal. in the articles that follow we will unleash the power of the web platform, thanks to HTML, CSS, and of course JavaScript.

Leave a Comment

Your email address will not be published. Required fields are marked *