This chapter introduces the fundamentals of the JavaScript programming language. Once used only for special effects, JavaScript has become the key building block for modern web applications. JavaScript can be used to programmatically access and dynamically manipulate any aspect of an HTML document’s appearance or content. It can be used to animate, move, transition, hide, and load content into parts of a page rather than refresh an entire page from the server. Environments and libraries such as Node.js and React have extended JavaScript’s reach to the server and to native mobile application development. This growing popularity has made detailed JavaScript knowledge an essential skill for anyone working in contemporary web application development. This chapter will focus on learning the fundamentals of the JavaScript programming language. Once these are mastered, you will be ready for the next chapter.

Note

JavaScript may not be an ideal first programming language for students. It is an easy language to start programming with in the sense that no additional tools like compilers are needed, and indeed, this is part of its broad appeal. On the other hand, the language has many idiosyncrasies and complexities that make full mastery of the language challenging. This chapter (and book) doesn’t have the space to teach the basics of programming; instead it endeavors to teach JavaScript. For that reason we expect the reader of this chapter to already have some familiarity with another programming language before learning about JavaScript.

It should also be noted that even for experienced programmers, some aspects of JavaScript can be initially confusing. This first chapter on JavaScript covers most of the essentials of the JavaScript programming language. Some of these essentials are not, however, immediately essential. That is, when you are first learning JavaScript, some readers might want to initially skip over some of the content in this chapter that is more advanced or tricky; later, when you (or your students if you are an instructor) gain more experience with the language, you can go back and learn about some of the more advanced topics.