DEV Community

Discussion on: JS fundamentals: const vs var vs let?

Collapse
mse99 profile image
Mohamed Edrah • Edited on

JS behaves much more like a compiled language than an interpreted one, the code has to be parsed first it then compiled regardless of whether or not the compiled code is machine code or some other byte code format that gets interpreted, the point is JS code gets compiled it's hard to imagine that a production quality is engine parsing the code into an AST and not compile it and optimize it.

Hoisting doesnt move anything, again by move I mean re arranging the code so the declaration is on top of the scope that doesnt actually happen .... when the code gets compiled instructions to register variables are compiled and executed first that it's the engine doesnt rearrange or pre process anything it just turns your code into an efficient executable binary, that's how most JS engine execute code these days and yes JIT compilation IS a property of the language.

Thread Thread
pentacular profile image
pentacular

"compiled language" and "interpreted language" are nonsensical terms.

There are python compilers, and there are C interpreters.

These are implementation strategies which can be applied to any language.

Hoisting does effectively rearrange the code so that the declarations are at the top of the scope.

See the algorithm in 18.2.1.3 of ecma-international.org/publication... for example.

JIT compilation is not part of the language specification.

I suggest reviewing the language specification, as it may clarify many of these issues for you.