Skip to Main Content
JavaScript & jQuery: The Missing Manual, 2nd Edition
book

JavaScript & jQuery: The Missing Manual, 2nd Edition

by David Sawyer McFarland
October 2011
Intermediate to advanced content levelIntermediate to advanced
535 pages
18h 20m
English
O'Reilly Media, Inc.
Content preview from JavaScript & jQuery: The Missing Manual, 2nd Edition

Chapter 3. Adding Logic and Control to Your Programs

So far you’ve learned about some of JavaScript’s basic building blocks. But simply creating a variable and storing a string or number in it doesn’t accomplish much. And building an array with a long list of items won’t be very useful unless there’s an easy way to work your way through the items in the array. In this chapter, you’ll learn how to make your programs react intelligently and work more efficiently by using conditional statements, loops, and functions.

Making Programs React Intelligently

Our lives are filled with choices: “What should I wear today?”, “What should I eat for lunch?”, “What should I do Friday night?”, and so on. Many choices you make depend on other circumstances. For example, say you decide you want to go to the movies on Friday night. You’ll probably ask yourself a bunch of questions like “Are there any good movies out?”, “Is there a movie playing at the right time?”, “Do I have enough money to go to the movies (and buy a $17 bag of popcorn)?”

Suppose there is a movie that’s playing at just the time you want to go. You then ask yourself a simple question: “Do I have enough money?” If the answer is yes, you’ll head out to the movie. If the answer is no, you won’t go. But on another Friday, you do have enough money, so you go to the movies. This scenario is just a simple example of how the circumstances around us affect the decisions we make.

JavaScript has the same kind of decision-making feature called

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

JavaScript & jQuery: The Missing Manual, 3rd Edition

JavaScript & jQuery: The Missing Manual, 3rd Edition

David Sawyer McFarland
JavaScript: The Missing Manual

JavaScript: The Missing Manual

David Sawyer McFarland
JavaScript: Best Practice

JavaScript: Best Practice

James Kolce, Moritz Kroger, Ivan Curic, Samier Saeed, Jeff Mott, M. David Green, Craig Buckler

Publisher Resources

ISBN: 9781449317812Supplemental ContentErrata Page