All You Need to Know, and Nothing You Don't, to Write JavaScript for the Web and Beyond JavaScript plays a key role in modern software development, not only because it is the only language that runs inside virtually all web browsers, but also because it has become widely used for back-end and general-purpose development as well. Although JavaScript is a big language, you don't need to learn "everything" about it to get started, just how to use it efficiently to solve real problems. In Learn Enough JavaScript to Be Dangerous, renowned instructor Michael Hartl teaches the specific concepts, skills, and approaches you need to be professionally productive. Even if you've never programmed before, Hartl helps you quickly build technical sophistication and master the lore you need to succeed. Treating JavaScript as a general-purpose language right from the start, Hartl offers examples for creating dynamic effects in browsers and for writing scripts and modules using Node.js. Focused exercises help you internalize what matters, without wasting time on details pros don't care about. Soon, it'll be like you were born knowing this stuff—and you'll be suddenly, seriously dangerous . Learn enough about . . . Rapidly deploying a simple JavaScript app to the live Web Working with strings and other native JavaScript objects Applying functions and elegant, powerful functional-programming techniques Creating new objects with both properties and methods Writing tests and improving code with test-driven development (TDD) Developing and using self-contained, modular NPM software packages Adding interactivity with event listeners, dynamic HTML forms, and DOM manipulation Writing useful, nontrivial JavaScript shell scripts Building an industrial-grade interactive website with JavaScript, from start to finish Michael Hartl's Learn Enough series includes books and video courses that focus on the most important parts of each subject, so you don't have to learn everything to get started—you just have to learn enough to be dangerous and solve technical problems yourself. Register your book for convenient access to downloads, updates, and/or corrections as they become available. See inside book for details. Cover Half Title Title Page Copyright Page Contents Preface About the Author Chapter 1 Hello, World! 1.1 Introduction to JavaScript 1.2 JS in a Web Browser 1.2.1 Deployment 1.2.2 Exercise 1.3 JS in a REPL 1.3.1 Browser Console 1.3.2 Node Prompt 1.3.3 Exercise 1.4 JS in a File 1.4.1 Exercise 1.5 JS in a Shell Script 1.5.1 Exercise Chapter 2 Strings 2.1 String Basics 2.1.1 Exercise 2.2 Concatenation and Interpolation 2.2.1 The Backtick Syntax 2.2.2 Exercises 2.3 Printing 2.3.1 Exercise 2.4 Properties, Booleans, and Control Flow 2.4.1 Combining and Inverting Booleans 2.4.2 Bang Bang 2.4.3 Exercises 2.5 Methods 2.5.1 Exercises 2.6 StringIteration 2.6.1 Exercises Chapter 3 Arrays 3.1 Splitting 3.1.1 Exercises 3.2 Array Access 3.2.1 Exercises 3.3 Array Slicing 3.3.1 Exercises 3.4 More Array Methods 3.4.1 Sorting and Reversing 3.4.2 Pushing and Popping 3.4.3 Undoing a Split 3.4.4 Exercises 3.5 Array Iteration 3.5.1 Exercises Chapter 4 Other Native Objects 4.1 Math and Number 4.1.1 More Advanced Operations 4.1.2 Mathto String 4.1.3 Exercises 4.2 Dates 4.2.1 Exercises 4.3 Regular Expressions 4.3.1 Regex Methods 4.3.2 String Methods 4.3.3 Exercises 4.4 Plain Objects 4.4.1 Exercise 4.5 Application: Unique Words 4.5.1 Map 4.5.2 Exercises Chapter 5 Functions 5.1 Function Definitions 5.1.1 Sorting Numerical Arrays 5.1.2 Fat Arrow 5.1.3 Exercise 5.2 Functions in a File 5.2.1 Exercises 5.3 Method Chaining 5.3.1 Caveat Emoji 5.3.2 Exercises 5.4 Iteration for Each 5.4.1 Exercises Chapter 6 Functional Programming 6.1 Map 6.1.1 Exercise 6.2 Filter 6.2.1 Exercise 6.3 Reduce 6.3.1 Reduce, Example 1 6.3.2 Reduce, Example 2 6.3.3 Functional Programming and TDD 6.3.4 Exercises Chapter 7 Objects and Prototypes 7.1 Defining Objects 7.1.1 Exercise 7.2 Prototypes 7.2.1 Exercise 7.3 Modifying Native Objects 7.3.1 Exercises Chapter 8 Testing and Test-Driven Development 8.1 Testing Setup 8.1.1 Exercise 8.2 Initial Test Coverage 8.2.1 Pending Tests 8.2.2 Exercises 8.3 Red 8.3.1 Exercises 8.4 Green 8.4.1 Exercise 8.5 Refactor 8.5.1 Publishing the NPM Module 8.5.2 Exercises Chapter 9 Events and DOM Manipulation 9.1 A Working Palindrome Page 9.1.1 Exercise 9.2 Event Listeners 9.2.1 Exercise 9.3 Dynamic HTML 9.3.1 Exercise 9.4 Form Handling 9.4.1 Exercises Chapter 10 Shell Scripts with Node.js 10.1 Reading from Files 10.1.1 Exercise 10.2 Reading from URLs 10.2.1 Exercise 10.3 DOM Manipulation at the Command Line 10.3.1 Exercises Chapter11 Full Sample App: Image Gallery 11.1 Prepping the Gallery 11.1.1 Prepping the JavaScript 11.1.2 Exercise 11.2 Changing the Gallery Image 11.2.1 Exercises 11.3 Setting an Image as Current 11.3.1 Exercise 11.4 Changing the Image Info 11.4.1 Deploying 11.4.2 Exercise 11.5 Conclusion 11.5.1 Learning More JavaScript 11.5.2 Learning a New Language Index