1

-2. How JavaScript works-

PARSERS AND THE ABSTRACT SYNTAX TREE.

JavaScript is not read by the browser directly, this has to be compile and optimize into bytecode before by an Engine. The first process is the parse, the code is divided into tokens, keywords that structure the file. Here is also where Syntax Errors are caught. This make that bundling and code splitting important as best practice.
There is two ways to make parsing: Eager Parsing, this find Errors, build the ATS and build scopes; and Lazy Parsing, faster, doesn’t build AST and partially scopes.
Demo – Tokens: are the minimal components of the file, every each of one has a value and a type.
Abstract Syntax Tree (AST): It is a graph that structure the login of out program, it is very used not only by the engine but trans pilers, bundlers, type checkers, etc.

ABSTRACT SYNTAX TREE – PRACTICE.

In this case we are working with ESLint a type checker, to set our own rules there is this website where we can test the rules we are going to implement  https://astexplorer.net/
Once here and setting before for babel-Eslint for the new version of Eslint. We can start building the function that will help to detect the error and send the message, also it is possible to autocorrect the errors.
In this example we set a rule that notice if the const declaration when is a number is in upper case or lower case, being an error lower case. Also we set the autocorrect to transform into Uppercase the errors.

HOW JAVASCRIPT ENGINE WORKS.

After setting the structure of the code now is when the engine of the browser take that file and compile it into bytecode, it is not machine code (binary language), but it is close.
While reading the file the engine can learn and optimize the code, this that can look helpful it can be the cause of many errors like hoisting.

EVENT LOOP.

As we know JavaScript is synchronous, one task by task but it can get asynchronous behaviour giving duties to the browser. But these are not implemented straight away, they queue in call-back stack and the Event Loop is a watcher of the call-stack, stack of tasks proper of the Engine, and when this is empty then Event Loop will transfer those duties result to the Engine to be finished.
Before queueing them the Event Lopp schedule them but in case of promises their

Escribe tu comentario
+ 2