The best way to learn a programming language is to do it, find some project that you want to work on and starts working on it. I have a bad habit of just watching hours long youtube tutorial on a language ? but then after that I barely remembers anything, but it gives you an idea of what u can do with it. Normally what i do is I watch the video first, then starts to work on the project at the same time searching more on how I do it. Slowly coding your project, I am sure you will be able to remember what u coded
Books are definitely one of the best resources to learn. Books are the most coherent source of learning, and each book is the result of a writer's many years of endeavor, so that the author selects and writes one part of his book obsessively. Books are also the most complete source of learning and include everything.
I believe learning programming from the book for beginners is very informative and useful because it involves all the concepts, and I suggest this at least to begin with. Also, programming books as a good reference can always help you whenever necessary.
I find that having a solid IDE which has a debugger embedded helps significantly.
I hate having to remember all the classes and methods in Java/JS, however the "best" IDEs (for me) will give you code completion/hints.
Programming PHP, for instance, is tough if you rely only echo/print_r/var_dump for debugging. However, a decent step by step debugger with watches (hopefully in the tooltip of the mouse) makes the job of finding bugs/mistakes ever so easier.
Thus, having a local development/sandbox environment (for speed of updating/debugging), a good IDE and debugger will add learning from your own mistakes to the mix. And that way is the best one I have found to learn programming.
There are three important parts to learning a programming language:
2- Practice with functions
3- Create a program with what you learned
You can use websites, books and programming classes to learn. I personally suggest the first two to you (websites and books).
After learning, in order to be able to consolidate what you have learned in your mind, you must practice with what you have learned. Create different functions and if you forgot something, try it again.
After consolidating what you have learned, now is the time to create programs. To do this, first draw a program on paper (what you want the program to do) and then create it with programming.
It is handy, you may not be able to make great programs at first, but then your programs will gradually grow.
With these 3 simple tasks, you can learn the programming language you want.