Course contents
- 01Variables
- 02Primitive Data Types
- 03Operators
- 04Conditionals
- 05Arrays
- 06Array methods and properties
- 07Objects
- 08Functions
- 09Callbacks
- 10Arrow functions
- 11Promises
- 12Async and await
- 13Loops
- 14DOM Manipulation
- 15Syntax parser
- 16Execution context and hoisting
- 17Call stack
- 18WebAPI and setTimeout
- 19Closures
- 20Function Constructors and Prototypes
- 21By value vs by reference
Syntax parser
Your computer can’t read JavaScript code. When you run JavaScript code, a compiler converts your code into a set of instructions that machines can understand. The syntax parser is part of this compiler. It goes through your code character by character, and determines if the syntax is valid JavaScript or not before executing your code.

In this case, it saw that the characters “f” “u” “n” “c” “t” “i” “o” and “n” declared a function. Now, it expects a certain type of behavior: if there would’ve been an extra character, for example “functiona”, it would throw an error.
The syntax parser parses this into an AST (Abstract Syntax Tree). Although the real AST is way more complex, a way to visualize what the parser would produce in this case is:


An example of how an actual tree looks, can be seen using esprima.

You can also find more examples on its online editor https://esprima.org/demo/parse.html#.
References and further reading
- MDN: Lexical grammarHow source text is split into tokens.
- Wikipedia: ParsingThe general idea behind a parser.