If you are new to JavaScript and want to start writing code, I highly suggest JavaScript Step by Step. The book starts off providing the foundational basics including what is JavaScript, what it does (and doesn’t do), and a bit about the history. With a clearer understanding of what to expect and the potential issues, then we look to actual code.
As the title suggests, coding is presented step by step. We start off with simple exercises and gradually work in each new concept. I’ve always thought that the best way to learn code is through doing. By doing this step by step, you begin to understand what happens and the potential problems that you could encounter with each command or variable. Once you have the basics, you can add layers of complexity that will make your script usable.