Like Sandeep Panda and Peter Scheler said, building things is the most powerful way to learn, but you cannot just sit down and start buiding project after project without knowing the basic syntax and fundamentals.
Using books and video courses is a great way to get started. Interactive courses are even better. Whatever you choose, remember one - start typing code from the very beginning. That means that should take an example and write it by hand. Don't just copy/paste it. Play with it, change it, extend it, optimize it. When you fully know it, move to the next one.
When you have a solid foundation, start solving small problems. Codewars, Project Euler, r/dailyProgrammer, Project Rosetta are full of different kind of problems.
After that you can start building projects, if you haven't already. Again, start small. You will learn more from building ten small projects than building one big one. Every time you have an idea, write it down. I have a Trello board full of project ideas from games to mobile applications. It's a great way of generating project ideas ahead of time.
Also, start teaching. That means you can write technical articles, answer questions on Hashnode or StackOverflow, help other beginners, give talks. Sky is the limit here. The best way to get a sence of whether you know the material or not is to explain it in the simplest way possible.