JavaScript for WordPress Forums Vanilla JavaScript 1.3.05 – confusion with newContent Reply To: 1.3.05 – confusion with newContent

#8264
Zac Gordon
Keymaster

Hi Mike,

When I went back to fix this I realized that actually newContent should be there.

As mentioned, there is a best practice to declare all variables at the top of a section of code even if you do not assign them values until later. Later in the code you will note that newContent is assigned a value. However, the best practice is to declare all of your variables at the top and the assign them specific values later on. So, this code you pointed out is actually correct.

Later in the course we will get into why it still seems to work when you don’t declare it first as a variable, and it has to do with the topic of Scope.

Thanks!