There are two steps to a variable: 1. It has to be declared before it’s used anywhere. 2. Then you assign any value to it.
But this can be done in various ways. When you know initially what value the variable is going to hold, then you can assign the value while it’s declared, as such: var allDocs = app.documents;
.
But what if you don’t know yet what value it’s going to hold initially, then you just declare it without any assignment, as such: var myPage;
, and then when you’re ready to assign anything to it, you do without declaring it again (because once a variable is declared it doesn’t have to be declared again), as such: myPage = myPages[j];
.
If you want to be able to write serious scripts then you need to have a basic understanding of the language. I would advise you to read the book Head First JavaScript. It’s an excellent book for absolute beginners.