JAVASCRIPT JOURNEY: DAY1

CHAPTER 1- WELCOME JAVASCRIPT(INTRODUCTION).

#teamtanayejschallenge

DISCUSSION OF JS OVER COFFEE?

JavaScript is known yet unknown according to me. JS is just like another C++, Java or Python .

js.PNG

Yes, JS needs tools to convert JS code into Machine Executable Code. Tools is nothing but some sort of compiler to do a lot of intermediate work.

The biggest myth revolves around when it is said that JS runs only in browser. This myth is hacked by JS engines( V8 and Spider Monkey) with their NodeJS implementation to convert standalone JS code.

With this, it is not needed to attach JS into HTML and hit reload every time.

Everything in JS happens inside execution context and JS is not possible without it.

What the heck is Execution Context?

It consists of two components : Memory Code

Memory refers to the placeholder for variable and functions stored as key/value pair. For say : key: value equals to a:10 or function :{…..}. Memory Component is also known as variable environment.

Code refers to the execution of program one line at a time . Also known as Thread of Execution. It is a thread in which code is executed one line at a time.

Is JavaScript synchronous single threaded language?

JS can execute one command at a time in a specific order. It can only go to a next line once the current line has been finished executing.

BEHIND THE SCENE OF JS:~

When you write JS program execution context is created. The execution context is created in two phases:~

  1. CREATION PHASE (Memory Creation Phase) where JS allocates memory to variables and functions.
  2. CODE EXECUTION PHASE says how code is executed after JS allocation.

So when you run a function whole brand new execution context is created. It is executed in phases !

js1.png

So try to visualize: As soon as the whole JS program runs , global execution context is created(GEC) with two components Memory and Code with two phases Memory Creation and Code Execution.

Memory Execution means allocation of memory to variables/functions such that variable : undefined and function : {code}

Code Execution means JS program is executing line by line. It replaces “undefined” with value in case of variable and then function is invoked eventually.

So when the function is invoked , whole brand new execution context is created.

Again the same process of creation of execution context is created such that variables got allocation of memory where code execution phase calculates value for that.

After that control is returned and control is back to the execution context from which originally function was invoked.

Do you think JS do so much work??

Yes , indeed it is but JS does this very beautifully . It handles creation, update and deletion of execution context via managing stack i.e. call stack!

JS has its own call stack.

Call Stack is a stack .

js3.jpeg

Call stack maintains the order of execution of Execution Context popularly known by names : Program Stack , Control Stack , Run Time Stack and Machine Stack.

Summary:-)

So this article will help you learn what is JavaScript with its essence and some beautiful terms that acts as a foundation for it.