And inside here, we can quickly see inside the body of the arrow function, we can see it has a block statement, and in block statement, we have got an if statement specifically, and we have got a return statement, right?
Let's explore the if statement first. Inside the if statement, we can see the consequent. It's also a block statement with another return type altogether. This will essentially be the string which I'm returning here, and inside the if statement, inside the test, we can see the identifier here, right?
Just like how we saw in this particular case, in that, the identifier was 1 equal to, and in this case, we have triple equal to. The left-hand side would be the dog name, so dog name, it's not the value, right? It's the variable name, and that is the reason it says name here. And on the right-hand side of things, we can see the again another variable with which we are trying to compare. And here you can see as mentioned earlier, the type is const, and inside this, it's one and the same thing, but it's a call expression. It comes in when it seems that you're trying to call a particular function. It also talks about the argument. And inside the argument, also, it's giving the name. Because this variable is pointing to this string. We are not directly passing this string, right?
So, and inside the calling, whatever the name of the function, we are trying to call. This is how an AST looks like. And as I mentioned earlier, just by looking at the AST structure, you can derive the code. But of course, it will take a lot of time to do that because this is more human readable than the AST itself. So, this is not just the only representation of AST. You can also try out the JSON part, which throws in everything at once. This was the T-representation. And we also have something called join.js. Let me just copy paste this. I can just do show ast and it will showcase everything you need to know. And this is also a good representation. It gives you a verbose explanation of what all nodes you have, what tokens you have. It lists down the keywords, identifiers, punctuators, and everything you need basically. I can just go to the PNG version of it. And this is also another tree structure, but I feel like this is a bit verbose. And it's more human readable, you know? Because it has got like it has got everything. You can just read it through and understand this by looking at it. So, that's what AST is. Let's talk a bit about Babel now.
Comments