In short, based on your example, this means that JS compiler will create a variable called body inside your post function at the very top of the function, which has the initial value of undefined. This happens because you used the var keyword for it, in contrast to const/let.

Only in the case of JSON.parse() working properly, the value of the body variable will be set. In case of this failing (which happens to you as it seems) or getting an error, body will remain undefined permanently, meaning you cannot access its properties such as method, as it is not an object.

Solutions depend on what you want to achieve here:

You can put the rest of the code inside try/catch aswell

You can add an additional check for body aswell

You could refactor the code a bit to be more readable (which is always subjective of course and depends on the coding style)