DEV Community

Discussion on: Why (! + [] + [] + ![]).length is 9

Collapse
 
karataev profile image
Eugene Karataev

If I'm not sure what's going on with the JS code, I use ASTexplorer to look at the code with the compiler's eyes. It converts a code string into the tree of instructions to be executed by the compiler step by step.
But sometimes text representation of a tree is not expressive enough, so I built a little tool which visualizes an AST tree.
For (! + [] + [] + ![]).length AST in graph form looks like this:
ast
In runtime calculations starts from the bottom left and flow to the top.

Collapse
 
tomasforsman profile image
Tomas Forsman

love this!