Origin and Initial Design Goals
- 1995: Crafted by Brendan Eich within a mere span of 10 days, the language initially bore the moniker “Mocha.”
- 1997: The introduction of the ECMAScript standard marked a pivotal moment, ushering in the formalization of this dynamic language.
- User-Friendly Design: The language was meticulously designed to be accessible and user-friendly, catering to both designers and programmers.
Changes in ECMAScript Standards
Table: Versions and Milestones
|1997||ECMAScript 1||Basic functionalities|
|1999||ECMAScript 3||Regular expressions, try/catch|
|2009||ECMAScript 5||JSON support, strict mode|
|2015||ECMAScript 2015||Arrow functions, classes, let and const, Promises|
|2016||ECMAScript 2016||Exponentiation operator, Array.prototype.includes|
|2017||ECMAScript 2017||Async/Await, Object.entries()|
|2018||ECMAScript 2018||Rest/Spread properties, async iteration|
|2019||ECMAScript 2019||Array.prototype.flatMap, Object.fromEntries|
|2020||ECMAScript 2020||Nullish coalescing operator, Optional Chaining|
Compiled vs. Interpreted Languages
Characteristics of Compiled Languages
- Compilation Phase: In the realm of compiled languages, a pivotal characteristic is the presence of a distinct compilation phase. During this pre-execution stage, the source code undergoes transformation into machine code, a process commonly referred to as compilation.
- Static Typing: A prevalent feature among compiled languages is static typing. In this paradigm, developers are obliged to declare variable types prior to compile-time, enhancing code robustness.
- Optimization: Another hallmark trait is the emphasis on code optimization within the compiler itself. This optimization effort is geared toward enhancing code performance, effectively offloading the heavy lifting before execution.
- Machine-Specific Nature: Compiled languages often yield machine or platform-specific code, necessitating recompilation when targeting different systems to ensure compatibility.
- Error Validation: The compilation phase also serves as a critical checkpoint for identifying and addressing syntax and type-related errors, affording developers the advantage of catching and rectifying issues before execution.
|Language||Static/Dynamic Typing||Compilation Phase|
Characteristics of Interpreted Languages
Interpreted languages also have distinct features:
- Just-In-Time (JIT) Execution: Interpreted languages distinguish themselves by employing Just-In-Time (JIT) execution. This methodology entails the interpretation of code on a line-by-line basis, occurring immediately before actual execution.
- Dynamic Typing: A notable hallmark of interpreted languages is their accommodation of dynamic typing. This feature permits variable types to be ascertained at runtime, offering flexibility and adaptability in coding.
- Portability: In contrast to compiled languages, interpreted languages eschew the creation of machine-specific binaries. Consequently, the resulting code is typically more portable, capable of traversing diverse platforms with ease.
- Runtime Error Handling: Interpreted languages adopt a runtime-centric approach to error handling. Rather than catching errors before execution, issues are typically identified and addressed during the execution phase.
|Language||Static/Dynamic Typing||JIT Execution|
Parsing and Abstract Syntax Tree
- Lexical Analysis: The code is meticulously tokenized, breaking it down into discrete, individual components or tokens.
- Syntax Analysis: These tokens are then methodically arranged into a hierarchical Abstract Syntax Tree (AST), creating a structured representation of the code’s syntactic structure.
Interpretation for Quick Execution
- Executes code line-by-line or block-by-block.
- Translates to machine code just before execution.
- Does not store this machine code for future use.
Profiling for Optimization
As the interpreter runs the code, it collects profiling data. This data provides insights into which parts of the code are executed frequently—known as “hot paths.”
- Frequency of function calls.
- Loop iterations.
- Frequently accessed variables.
JIT Compilation Steps:
- Identification of hot paths from profiling data.
- Compilation of these paths into optimized machine code.
- Storage of this machine code for quick future executions.
Table for Mechanisms
|Parsing to AST||Sometimes||Yes|
To dissect the JIT process even further, one could segment it into a few critical steps:
- Hot Code Identification: As the interpreter goes through the code, it earmarks frequently used or computationally heavy segments—referred to as “hot code.”
- Execution: The machine code runs, effectively eliminating the need to interpret those particular sections again, thus speeding up the program’s performance.
Q: Is JS compiled?
Q: What are some examples of compiled and interpreted languages?
A: Compiled languages include C, C++, Rust, and Go. Interpreted languages include Python, Ruby, and PHP.