

These are simple examples, and in practice graphs can encode large amounts of data. Here's a simple graph connecting node A to node B:Īt a very basic level, if you were to write this in Javascript, it could look like this:Įnter fullscreen mode Exit fullscreen mode You can travel from one node to another via the edge between them.

A graph can mix objects and arrays as well, nesting one kind within the other to whatever degree of complexity.Įach node and edge can contain information. Graphs consist of "nodes" and "edges", and can be represented by (often nested) objects or arrays. (You can also skip ahead to learn more about ASTs or look at these tools to make and use an AST yourself.) In order to understand ASTs we have to understand graphs.
EVERYWHERE BUT ON SOFTWARE
And a graph is a very useful type of data structure, ubiquitous in software engineering. This one is specifically for the above sample code declaring function foo(bool).Īn AST is a "tree", which is a kind of graph.

But under the hood VS Code uses code to do this! How?Īn AST is a data structure that encodes abstract information about a piece of code. It's almost as if VS Code has the ability to understand the semantics of code. But if we change the condition to true VS Code knows we will always run that block and (if there is an inevitable return inside) never reach the final line: If we have a conditional statement, VS Code accurately evaluates the potential for us to hit the code outside of it:īool could turn out to be false after all. So how in the world does VS Code know which lines of code won't be used in the future, when the code finally does run? Isn't it wonderful how VS Code grays out obsolete lines of code? Oops, my return statement is on line 3.
