SKIP THE SHIPPING
Use code NOSHIP during checkout to save 40% on eligible eBooks, now through January 5. Shop now.
Video accessible from your Account page after purchase.
Register your product to gain access to bonus material or receive a coupon.
7+ Hours of Video Instruction
In Learn Enough JavaScript to Be Dangerous: Write Programs, Publish Packages, and Develop Interactive Websites with JavaScript, renowned instructor Michael Hartl teaches the concepts, skills, and approaches you need to be professionally productive with JavaScript for both interactive websites and for general-purpose programming.
Overview
JavaScript is the programming language of the World Wide Web, and it is also developing into a powerful general-purpose programming language. You'll love the way this series teaches programming with JavaScript, where you don't need to learn "everything" about it--just how to use it efficiently to solve real problems. Best-selling author Michael Hartl teaches JavaScript by getting you started writing practical and modern JavaScript programs as fast as possible, with a focus on the real tools used every day by software developers.
Even if you're new to programming, Hartl helps you quickly build technical sophistication as you gain a solid understanding of JavaScript for object-oriented and functional programming, including making JavaScript modules with test-driven development and 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.
About the Instructor
Michael Hartl is the creator of the Ruby on Rails Tutorial, one of the leading introductions to web development, and is cofounder and principal author at Learn Enough. Previously, he was a physics instructor at the California Institute of Technology (Caltech), where he received a Lifetime Achievement Award for Excellence in Teaching. He is a graduate of Harvard College, has a PhD in physics from Caltech, and is an alumnus of the Y Combinator entrepreneur program.
Skill Level
Learn How To
Who Should Take This Course
Course Requirements
Lesson Descriptions
Lesson 1: Hello World!
In Lesson 1, you begin your study of JavaScript with four variations on the time-honored theme of a "Hello, World!" program. The main purpose of "Hello, World!" is to confirm that your system is correctly configured to execute a simple program that prints the string "Hello, World!" or some close variant to the screen. By design, the program is simple, enabling you to focus on the challenge of getting the program to run in the first place. In order to give you the best broad-range introduction to programming with JavaScript, Learn Enough JavaScript to Be Dangerous uses four main methods: one, front-end JavaScript programs running in the user's browser; two, an interactive prompt with a Node.js read, evaluate, print, loop, also called a REPL; three, standalone JavaScript files, including the Node Package Manager; and four, shell scripts, introduced in Learn Enough Developer Tools to Be Dangerous. Since the original and still most common application of JavaScript is to write programs that execute on the web, we'll start by writing and deploying a program to display "Hello, World!" in a web browser. We'll then write a series of three programs using the JavaScript execution system, Node.js, first in the node REPL, then in a JavaScript library file called hello.js, and finally, in an executable shell script simply called hello.
Lesson 2: Strings
Lesson 2 covers strings, probably the most important data structure on the Web since web pages ultimately consist of strings and characters sent to and from the browser. Many other kinds of programs require string manipulation as well. Thus, strings are a great place to start your Ruby programming journey. The lesson starts with what strings are and how to create them, including both single- and double-quoted strings. You then learn how to join, or concatenate, one string to another. Next, you learn how to print to the screen from the terminal window. As part of this, you see your first examples of JavaScript boolean variables and control flow. Finally, you learn how to iterate over strings with for loops, enabling you to access strings one character at a time.
Lesson 3: Arrays
In Lesson 3, you learn about the array data type, which is the general JavaScript container for arbitrary elements in a particular order. You start by explicitly connecting strings and arrays via the string split method and then learn about various array methods throughout the rest of the lesson. After learning to split strings you see how to access elements in the resulting array. You discover that the same syntax works on strings, further deepening the connection between the two data types. Next, you learn a variety of additional array methods beginning with selecting both single elements and multiple elements at once using array slicing, including a clever technique using negative indices to select the last element in an array. Then you learn how to sort arrays, discovering en route that JavaScript's default sorting algorithm is less than useful for numerical arrays, an issue addressed in Lesson 5. You also learn how to reverse an array, an ability put to good use later in the tutorial when learning to detect palindromes. Next, you see how to add and remove array elements using push and pop and then learn how to undo a string split with an array join. Finally, you learn how to iterate through arrays using the same kind of for loop covered in Lesson 2, which is valuable preparation for the more advanced techniques covered in Lessons 5 and 6.
Lesson 4: Other Native Objects
In Lesson 4 you continue with the tour of some other important JavaScript objects, which gives you a chance to learn about math, dates, regular expressions, and generic objects. Like most programming languages, JavaScript supports a large number of mathematical operations right out of the box, such as addition, subtraction, multiplication, and division. It also includes a math library. It also supports more advanced operations like logarithms and trigonometric functions. You also learn how to deal with dates in JavaScript, such as getting the year, the day, or the exact time. This gives you your first chance to use the new function, a so-called constructor function. That is the standard JavaScript way to create a new object. This lesson includes an introduction to the powerful subject of regular expressions, which were discussed briefly in Learn Enough Developer Tools to Be Dangerous in the context of text editors and the grep command. Often called regexes, regular expressions are a powerful mini language for matching patterns in text. You'll learn how to use regexes to quickly search strings for things like five digits in a row, thereby matching standard United States ZIP codes. The lesson ends with an introduction to plain objects in JavaScript. We'll use such objects to create collections of keyvalue pairs, sometimes known as associative arrays, which are like regular arrays but with strings instead of integers as indices. You apply this important object type to write your first substantial JavaScript program, a shell script to count the unique words in a text.
Lesson 5: Functions
In Lesson 5, you learn how to define JavaScript functions, which enables powerful techniques like forEach, which is covered in this lesson, and functional programming, which is the subject of Lesson 6. You begin with a discussion of a couple of equivalent ways to define JavaScript functions, including the more recent fat arrow notation, which can look really confusing if you haven't seen it before. As part of this, you learn how to sort JavaScript arrays numerically, thereby fixing a blemish encountered in Lesson 3. You begin your study of functions in the read-eval-print loop, that is, the REPL. Then you learn how to put your function definitions in a file for later use. The lesson also covers how to use multiple functions in a row, a technique known as method chaining. You use method chaining to make a first definition of a palindrome function to see if a string is the same forward and backward. The lesson ends with the discussion of the forEach method for iterating through arrays, which often provides a more convenient way of processing array elements than the for loop introduced in Lesson 2.
Lesson 6: Functional Programming
Having learned how to define functions and apply them in a couple of different contexts, in Lesson 6 you take your programming to the next level by learning the basics of functional programming. This is a challenging lesson and you may have to watch it a couple of times to absorb everything, but the rewards are rich indeed. The lesson focuses on a triumvirate of functions commonly used in functional programming known as map, filter, and reduce. The first of the examples is the map function, which lets you map a function over an array of elements. It is often a powerful alternative to looping. So far, you have been using a style of coding known as imperative programming, but you see how to use map to take a five-line loop and condense it to a single line. This sort of compression is common in functional programming. The second function covered is filter, which enables you to filter your data based on some boolean criterion. This lets you run through an array and filter out anything that doesn't match your criterion. For example, you could take an array of integers and filter for only numbers evenly divisible by two, giving us a quick way to select only the even numbers in the array. Our third function is the mighty reduce, which is exactly the kind of powerful technique that can take lots of examples to really sink in but enables us to write remarkably clean and concise code. Because reduce, and indeed all functional techniques, can be challenging to understand even for experienced developers, it's especially powerful when combined with test-driven development, which is covered in Lesson 8, but first you need to learn how to define objects of your own.
Lesson 7: Objects and Prototypes
In Lesson 7 you learn how to make more general versions of JavaScript objects, ones that have both properties, which are data, and methods, which are functions, attached to them. There is a dizzying variety of ways to define objects in JavaScript, but this lesson focuses on one of the most classic ways, which is to use functions, which were first covered in Lesson 5. The result will be an object constructor function that can be used to create or instantiate a new object called an instance using the new method you saw in Lesson 4. This will give you the background needed to understand JavaScript's object system, which is based on template objects and a prototype chain. If that doesn't seem perfectly clear, don't worry, it's not. Nobody ever understood object systems by hearing definitions like that one. Instead, we look at a series of objects of increasing complexity, enabling you to understand the essence of JavaScript objects by generalizing from concrete examples. In particular, you create a Phrase object that knows whether or not the phrase is a palindrome. You then add a TranslatedPhrase object that overrides the main palindrome method and substitutes a translated phrase instead. Then you use the powerful, even dangerous, practice of modifying native JavaScript objects. This enables you to modify the string prototype itself, giving every string the ability to tell whether or not it is a palindrome.
Lesson 8: Testing and Test-Driven Development
Although rarely covered in introductory programming tutorials, automated testing is one of the most important subjects in modern software development. Accordingly, Lesson 8 gives you an introduction to testing in JavaScript, including a first look at test-driven development, or TDD. Test-driven development came up briefly in Lesson 6, which promised that you would use testing techniques to add an important capability to finding palindromes, namely, being able to detect complicated palindromes such as "A man, a plan, a canal--Panama!" or "Madam I'm Adam." This lesson fulfills that promise. You start by setting up your system for testing using the popular Mocha testing framework. The strategy for testing the current palindrome code and extending it to more complicated phrases is as follows: one, set up your system for automated testing; two, write automated tests for the existing palindrome functionality; three, write a failing test for the enhanced palindrome detector, also known as red (the first step in the TDD cycle known as red-green-refactor); four, write possibly ugly code to get the test passing, also known as green, which is the second step in the cycle; five, refactor the code, which involves changing its form without changing its function. The test suite should remain green even after refactoring, thereby completing the red-green-refactor cycle. As it turns out, learning how to write JavaScript tests will also give you a chance to learn how to create and publish self-contained software packages called NPM modules, another valuable skill for modern JavaScript programming.
Lesson 9: Events and DOM Manipulation
In Lesson 9, you return to JavaScript's native environment and put your newly created Node module to work in the browser, including our first example of manipulating the Document Object Model, or DOM. Specifically, you make a simple single-page JavaScript application that takes in a string from the user and indicates whether or not that string is a palindrome. The approach involves gradually increasing levels of sophistication, starting with a simple "hello world"style proof of concept. Then you add a prompt/alert design that will motivate the introduction of event listeners. This involves adding a piece of code that waits for a particular event to happen and then responds appropriately. In this case, the listener will wait for a button to be clicked and then prompt the user to enter a string, which will then test to see whether it's a palindrome. Next, you replace the alert with dynamic HTML inserted on the page itself. Finally, you add an HTML form, which is a more convenient method for entering data than a JavaScript prompt. As part of this, you update the event listener to respond by updating the page itself when the user submits the form, thereby creating a fully functional palindrome detector.
Lesson 10: Shell Scripts with Node.js
In Lesson 10, you return to the world of the command line and use Node.js to write three shell scripts of increasing sophistication. This use of JavaScript is currently less common than JavaScript in the browser, but it can be expected to grow as JavaScript, especially via Node and npm, continues to expand past its original web programming niche. These programs also serve as a useful foundation for similar programs written in languages more traditionally thought of as scripting languages, such as Perl, Python, and Ruby. Perhaps surprisingly, you will discover that the Document Object Model manipulation skills developed in Lesson 9 are still useful in shell scripts. Indeed, you extend your capability significantly in exactly the direction needed for the more advanced manipulations used in Lesson 11. The first program in this lesson shows how to use JavaScript to read and process the contents of a file from the file system. The next program then shows how to accomplish the similar feat of reading the contents of a URL. Finally, you write a real-life utility program.
Lesson 11: Full Sample App: Image Gallery
In Lesson 11, you apply the techniques from Lessons 9 and 10 to a real, industrial-grade website. In particular, this lesson extends the sample application from Learn Enough HTML, CSS and Layout to Be Dangerous to add a functional image gallery that dynamically changes images, CSS classes, and page text in response to user clicks. The result will be a professional-grade website deployed to the live Web.
About Pearson Video Training
Pearson publishes expert-led video tutorials covering a wide selection of technology topics designed to teach you the skills you need to succeed. These professional and personal technology videos feature world-leading author instructors published by your trusted technology brands: Addison-Wesley, Cisco Press, Pearson IT Certification, Sams, and Que. Topics include: IT Certification, Network Security, Cisco Technology, Programming, Web Development, Mobile Development, and more. Learn more about Pearson Video training at informit.com/video.
Video Lessons are available for download for offline viewing within the streaming format. Look for the green arrow in each lesson.
Introduction
Lesson 1: Hello World!
Topics
1.1 Introduction to JavaScript
1.2 JS in a Web Browser
1.3 JS in REPL
1.4 JS in a File
1.5 JS in a Shell Script
Lesson 2: Strings
Topics
2.1 String Basics
2.2 Concatenation and Interpolation
2.3 Printing
2.4 Properties, Booleans and control flow
2.5 Methods
2.6 String Iteration
Lesson 3: Arrays
Topics
3.1 Splitting
3.2 Array Access
3.3 Array Slicing
3.4 More Array Methods
3.5 Array Iteration
Lesson 4: Other Native Objects
Topics
4.1 Math and Numbers
4.2 Dates
4.3 Regular Expressions
4.4 Plain Objects
4.5 Application: Unique Words
Lesson 5: Functions
Topics
5.1 Function Definitions
5.2 Functions in a File
5.3 Method Chaining
5.4 Iteration for Each
Lesson 6: Functional Programming
Topics
6.1 Map
6.2 Filter
6.3 Reduce
Lesson 7: Objects and Prototypes
Topics
7.1 Defining Objects
7.2 Prototypes
7.3 Modifying Native Objects
Lesson 8: Testing and Test-Driven Development
Topics
8.1 Testing Setup
8.2 Initial Test Coverage
8.3 Red
8.4 Green
8.5 Refactor
Lesson 9: Events and DOM Manipulation
Topics
9.1 A Working Palindrome Page
9.2 Event Listeners
9.3 Dynamic HTML
9.4 Form Handling
Lesson 10: Shell Scripts with Node.js
Topics
10.1 Reading from Files
10.2 Reading from URLs
10.3 DOM Manipulation at the Command Line
Lesson 11: Full Sample App: Image Gallery
Topics
11.1 Prepping the Gallery
11.2 Changing the Gallery Image
11.3 Setting an Image as Current
11.4 Changing the Image Info
11.5 Conclusion
Summary