What's inside the world most popular programming language?
Tags: javascript, computerscience, webdev, beginners
Published: 2020-10-02 09:24:53

**A guide for the Ignorant Programmers.**

>I have tried to explain the concepts using very basic level of English language, so that a lot of newcomers can understand it without getting an imposter syndrome attack 😂


<hr>

# INTRODUCTION



> A programming language is like a natural, human language in that it favors certain metaphors, images, and ways of thinking.
> — Mindstorms: Children, Computers, and Powerful Ideas, Seymour Papert (1980)



<br/><br/> 
We define programming, as a general human activity, to mean the act of extending or changing a system’s functionality. Programming is a widespread activity that is done both by non-specialists (e.g., consumers who change the settings of their alarm clock or cellular phone) and specialists (computer programmers, the audience for this article).
<br/><br/> 

# **JavaScript** 
<br/><br/> 
It is **the** most popular Programming language today.
Today, Some of the most powerful Software are written in JavaScript.
But how many folks do actually understand this language?
Probably this the only language which is used(usually in scripts) before it is fully understood.
JavaScript is a powerful programming language but Weird at the same time.
Yet we can’t deny this fact that overall it is a beautiful Programming language.


<br/><br/> 
# So,
Have you Ever Wondered, how do those assortments of programming statements tell the Computer what to do?

> Statements like a = a + 2 are helpful for developers when reading and writing, but are not actually in a form the computer can directly understand.

<br/><br/> 

So an uncommon utility on the Computer (either a [*interpreter or a compiler*](https://www.youtube.com/watch?v=e4ax90XmUBc)) is utilized to decipher the code you compose into directions that a Computer can comprehend!

<br/><br/> 

## For some computer languages, this translation of commands is typically done from top to bottom, line by line, every time the program is run, which is usually called ***interpreting the code.***

<br/><br/> 
## For other languages, the translation is done ahead of time, called compiling the code, so when the program runs later, what’s running is actually the already compiled computer instructions ready to go.
<br/><br/> 

> It’s typically asserted that ***JavaScript is interpreted***, because your JavaScript source code is processed each time it’s run. [But that’s not entirely accurate.](https://softwareengineering.stackexchange.com/questions/138521/is-javascript-interpreted-by-design)
>
> The JavaScript engine actually compiles the program on the fly and then immediately runs the compiled code.


<br/><br/> 
In this article we will LEARN about some essential concepts that will help you to understand what actually happens under the hood.
And by the end of the article you will have a clear understanding of what actually happens when you write a JavaScript CODE

<br/><br/> 

Concepts that we will learn here are :

<br/><br/> 
1.  **Syntax Parsers**
2.  **Execution Contexts**
3.  **Lexical Environments**

<br/><br/> 

# **GOAL** : Understanding Syntax Parsers, Execution Contexts, and Lexical Environments in a Simple Language.

<br/><br/> 

> All three of these are complicated sounding terms that actually aren’t that difficult to understand.

<br/><br/> 
# SYNTAX PARSER :
A PROGRAM THAT READS YOUR CODE AND DETERMINES WHAT IT DOES AND IF IT’S GRAMMAR OR SYNTAX IS VALID


So when you write JavaScript it isn’t magically directly telling the computer what to do , you are [abstracted away](https://esprima.org/demo/parse.html) from all of that you are writing code! but then someone else or other people built programs that convert your JavaScript into something the computer can understand.

<br/>
Was that too hard to comprehend?
No, Right?

**Anyways**, 
Those programs are called compilers and at times they also have to do with interpreters, but those programs [*interpreters and compilers*](https://www.youtube.com/watch?v=e4ax90XmUBc) do the process the work of actually reading your code [*character by character*](https://www.youtube.com/watch?v=QXjU9qTsYCc) and determining if the syntax is valid and then implementing that syntax in a way the computer can understand,
<br/>
# **so when you’re thinking about your code think of it more like :**

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/zn48ky20tksa45isadtn.jpeg)

## **and a** [**program**](https://www.youtube.com/watch?v=e4ax90XmUBc) **that is going to convert what computer can understand !**

# Something like this:

<br/>
![Image for post](https://miro.medium.com/max/2212/1*FXhTiEYu4AhvEnp7YIFWUg.png)

<br/><br/> 

If you have a **function** with the variable, then that function and variable will be represented in memory but it’s being translated from what you have written what is more human readable to what the computer can understand. There’s a compiler or an interpreter between those two things and part of that is a ***syntax parser*** so, it’s going through your code
 
> **character by character like f /u/ n/ c/ t/ i/ o/ n**

# That is, it reads your code in characters



> and it says : Oh! that’s function 😃 ,So there should be a space after this ! and then the next thing I see up until the parenthesis **( )** will be the name of the function,

above ***Greet*** is next thing the computer sees up until the parenthesis **( )** so it assumes that ***Greet*** will be the name of the function.


And all this gets *translated by the systems that someone else wrote* but that also means that in that translation process ,the programmers who wrote the compiler can choose to do extra stuff .

<br/>
Your code is not what’s actually being given to the computer but a translation of it and so along the way the engine that is interpreting your code can decide to do other things those programmers could have chosen to do something else and in fact that’s going to come up as an important element of understanding JavaScript so that’s impacts parsers and thinking about the programs that are actually running every time you run your JavaScript code that intermediate program that’s creating your code.
<br/><br/> 
# LEXICAL ENVIRONMENT :
<br/>
> The *word lexical means having to do with words or grammar* so we’re talking about the code you’re writing it’s syntax it’s vocabulary !

<br/>

Now a **lexical environment** exists in programming languages in **which**,where you write something which is *important.*
<br/>

It sounds kind of funny but actually not every programming language is that way, but remember we said you might have some code.
<br/>
let’s say a function with a variable inside of it the variable sits lexically inside the function ,that is : *physically the code that you’re writing*
<br/><br/> 


![Image for post](https://miro.medium.com/max/1184/1*x4IKK3eLfWn6i7gutS0kcg.png)

<figcaption>function with a variable inside of it.</figcaption>

<br/><br/> 

that’s where it sits but remember we said that your code is not what’s actually given directly to the computer but it’s translated into something the computer can understand

<br/><br/> 

In programming languages **where the lexical environment is important** that means that where you see things written gives you an idea of where it will actually sit in the computer’s memory of how it will interact with other **variables and functions** and elements of the program and that’s because the program or the compiler that’s converting your code to those instructions cares about where you put things it makes decisions that syntax parts are going through everything makes decisions so when we talk about the lexical environment of something in the code we’re talking about where it’s written and what surrounds it got that.

<br/><br/> 
To help manage the code that is running there are lots of lexical environments areas of the code that you’re looking at physically but which one is currently actually running is managed via what’s called

# **EXECUTION CONTEXT:**

# **A WRAPPER TO HELP MANAGE THE CODE THAT IS RUNNING**

<br/><br/> 
> There are lots of lexical environments which one is currently running and managed via execution contexts.it contain things beyond what you have written in your code!

<br/><br/> 

And in execution context contains your code ,the running code and it’s running your code, but it also can contain things beyond what you’ve written in your code because remember again your code is being translated being processed by a whole other feature a whole other set of programs that someone else wrote and so it’s executing your code and it can do other things as well and that’s what’s happening inside JavaScript.

<br/><br/> 
**Execution context** is whole topic by itself which we will deal in some other article.

# How was the Post ? Tell me in the comments.