Skip to content
Vikyath Shirva

What is JavaScript? How does it work?

- Vikyath Shirva

This little article is an introduction to what JavaScript is and how it works, You have heard it everywhere Reactjs, node.js ... js js and all the other js..

Potions Class

How does it even work??

Okay let me break it down to you in the most simplest way possible, by the time you finish reading this, you will know what the hell does JavaScript do in the web. If you are reading this article right now, I am damn sure you know what a web browser is, you are literally reading this on it. So here we go, As raw and as basic as possible, "JavaScript " is a scripting language, its not a programming language in a strict sense, well.. let me explain, a programming language will do what you tell it to do, a scripting language will tell someone else to do it. So basically, JavaScript tells browser to do anything you ask it to do. If you ever tell it to replace an image by another one, it will go ahead and tell the browser to do it. That's all, it’s a scripting language. So how does this thing work in the browser ?

For any language to run it needs a place to run-in, meaning, as a human you need a space to live and exist and function, you need this earth as an environment to operate, similarly JavaScript also needs a space to operate and execute code. So, the environment it uses is commonly a web browser, there can be other places or like node.js web servers or any other application that accepts JavaScript code input. But, lets bring our attention to web browser for now.

When we write JavaScript code and run it in the web browser, there are a lot of stuff happening behind the scenes, allots of stuff that is too much for now to explain. The environment or the "Space", as in ,Earth for human beings, the web browser is for JavaScript; uses some kind of engine, that takes whatever code you write and runs it. So, this is like a little complicated software that runs JavaScript code, Google chrome uses an engine called v8, there are a lot of engines like this,such as Rhino, SpiderMonkey, let's just leave that aside for now.

Potions Class

Here's the first thing that happens in the engine. The code that is sent to the engine will be read by some part of engine called as a Parser

It's something more like a dictionary + grammar textbook for English, but for a certain programming language. So, a parser is a tool that will read your JavaScript code, line by line, and make sense out of it to the language of the computer, and checks for the syntax; meaning, the way it's supposed to be written for the computers, if, in case, everything is correctly written, then the parser will go to the next step, or else, it will show an error saying you didn’t write it properly.

Once you write it properly and parser understands your code, it will go to the next step and makes a new thing out of the code you sent in, this pops out something called as a "Abstract Syntax Tree"

what is an Abstract syntax tree?

Look, it sounds complicated than it actually is. Your computer or your device that you use to read a website, will have a processor, it only understands one language. That is Assembly.

Lets say you a have Spanish friend who doesn't speak English. The translator in between gives him an understanding of what you told him, that is something similar to what an abstract tree does;

Abstract syntax tree gives a way for the processor to refer to the grammer of the language you used to communicate

It converts your programming language that is JavaScript, to the processor, which knows a language called Assembly, this is also called as machine code.

This machine code goes in to the processor and does all the work, and pops an answer out to the environment where its running, that is your browser.

There you go

Potions Class

That's what JavaScript does on the web browser in a simple way.

There's much more to it, but I'll keep you posted and help you understand on the further posts.

© 2022 by Vikyath Shirva. All rights reserved.