Home > Store

JavaScript Absolute Beginner's Guide

Register your product to gain access to bonus material or receive a coupon.

JavaScript Absolute Beginner's Guide

eBook (Watermarked)

  • Sorry, this book is no longer in print.
  • Includes EPUB and PDF
  • About eBook Formats
  • This eBook includes the following formats, accessible from your Account page after purchase:

    ePub EPUB The open industry format known for its reflowable content and usability on supported mobile devices.

    Adobe Reader PDF The popular standard, used most often with the free Acrobat® Reader® software.

    This eBook requires no passwords or activation to read. We customize your eBook by discreetly watermarking it with your name, making it uniquely yours.

Not for Sale

Description

  • Copyright 2017
  • Dimensions: 7" x 9-1/8"
  • Pages: 350
  • Edition: 1st
  • eBook (Watermarked)
  • ISBN-10: 0-13-449864-X
  • ISBN-13: 978-0-13-449864-5

JavaScript Absolute Beginner's Guide

No experience necessary!


Make the most of JavaScript -- even if you've never programmed anything before. This book is the fastest way to learn JavaScript and use it together with CSS3 and HTML5 to create powerful web and mobile experiences. Learn how to do what you want, the way you want, one incredibly easy step at a time. JavaScript has never been this simple!


This is the easiest, most practical beginner’s guide to programming JavaScript with simple, reliable instructions for doing everything you really want to do! Here’s a small sample of what you’ll learn:

  • Learn why JavaScript is awesome
  • Organize your code with variables
  • Understand how functions make your code reusable
  • Use the popular if/else statement to help make a decision in code
  • Learn about switch statements and when to use them
  • Work with for, while, and do...while loops
  • Learn how to use global and local scope 
  • Understand what closures are 
  • Learn about the various places your code can live 
  • Understand how to write comments and good commenting practices
  • Learn about the basic types of objects you'll run into in JavaScript
  • Find out that pizza has an educational value beyond just being deliciously awesome
  • Understand how text is treated in JavaScript 
  • Learn how to perform common string operations
  • Use arrays to handle lists of data
  • Learn to create custom objects
Purchase of JavaScript Absolute Beginner's Guide in any format includes free access to the online Web Edition, which provides several special features to help you learn:
  • The complete text of the book online
  • Short videos by the author introducing each chapter
  • Interactive quizzes to test your understanding of the material
  • Updates and corrections as they become available
This Web Edition can be viewed on all types of computers and mobile devices with any modern web browser that supports HTML5.
Contents at a Glance
1 Hello, World!
Part I: The Basic Stuff2 Values and Variables3 Functions4 Conditional Statements: If, Else, and Switch5 Meet the Loops: For, While, and Do…While!6 Timers7 Variable Scope8 Closures9 Where Should Your Code Live?10 Commenting Your Code
Part II: It’s an Object-Oriented World11 Of Pizza, Types, Primitives, and Objects12 Strings13 When Primitives Behave Like Objects14 Arrays15 Numbers16 A Deeper Look at Objects17 Extending Built-in Objects18 Booleans and the Stricter === and !== Operators19 Null and Undefined20 Immediately Invoked Function Expressions
Part III: Working with the DOM21 JS, The Browser, and The DOM22 Finding Elements in the DOM23 Modifying DOM Elements24 Styling Your Content25 Traversing the DOM26 Creating and Removing DOM Elements27 In-Browser Developer Tools
Part IV: Dealing with Events28 Events29 Event Bubbling and Capturing30 Mouse Events31 Keyboard Events32 Page Load Events and Other Stuff33 Handling Events for Multiple Elements34 Conclusion

Sample Content

Sample Pages

Download the sample pages (includes Chapter 3 and the Index.)

Table of Contents

Introduction     1
Parlez-vous JavaScript?     2
Contacting Me/Getting Help     4
Chapter 1  Hello, World!     5
What Is JavaScript?     7
A Simple Example     8
    Code Editing Tools     8
    The HTML Document     9
Looking at the Code: Statements and Functions     10

PART I:  THE BASIC STUFF
Chapter 2  Values and Variables     13

Using Variables     14
More Variable Stuff     15
    Naming Variables     15
    More on Declaring and Initializing Variables     16
Chapter 3  Functions     19
What Is a Function?     22
    A Simple Function     22
Creating a Function That Takes Arguments     24
Creating a Function That Returns Data     27
    The Return Keyword     27
    Exiting the Function Early     28
Chapter 4  Conditional Statements: If, Else, and Switch     31
The If/Else Statement     32
    Meet the Conditional Operators     34
    Creating More Complex Expressions     36
    Variations on the If/Else Statement     38
    Phew     39
Switch Statements     39
    Using a Switch Statement     39
    Similarity to an If/Else Statement     42
Deciding Which to Use     44
Chapter 5  Meet the Loops: For, While, and Do…While!     47
The for Loop     49
    The Starting Condition     51
    Terminating Condition (aka Are we done yet?)     51
    Reaching the End     51
    Putting It All Together     52
Some for Loop Examples     52
    Stopping a Loop Early     53
    Skipping an Iteration     53
    Going Backwards     54
    You Don’t Have to Use Numbers     54
    Array! Array! Array!     54
    Oh No He Didn’t!     55
The Other Loops     55
    The while Loop     56
    The do…while Loop     56
Chapter 6  Timers     59
Meet the Three Timers     60
    Delaying with setTimeout     60
    Looping with setInterval     61
    Animating Smoothly with requestAnimationFrame     62
Chapter 7  Variable Scope     67
Global Scope     68
Local Scope     70
Miscellaneous Scoping Shenanigans     71
    Declarations Using var Do Not Support Block Scoping     71
How JavaScript Processes Variables     72
Closures     74
Chapter 8  Closures     77
Functions within Functions     78
When the Inner Functions Aren’t Self-Contained     81
Chapter 9  Where Should Your Code Live?     89
The Options on the Table     90
Approach #1: All the Code Lives in Your HTML Document     92
Approach #2: The Code Lives in a Separate File     93
    The JavaScript File     93
    Referencing the JavaScript File     94
So Which Approach to Use?     97
    Yes, My Code Will Be Used on Multiple Documents!     97
    No, My Code Is Used Only Once, on a Single HTML Document!     99
Chapter 10  Commenting Your Code     101
What Are Comments?     102
    Single Line Comments     103
    Multi-line Comments     104
Commenting Best Practices     106

PART II:  IT’S AN OBJECT-ORIENTED WORLD
Chapter 11  Of Pizza, Types, Primitives, and Objects     109

Let’s First Talk About Pizza     110
From Pizza to JavaScript     113
What Are Objects?     115
The Predefined Objects Roaming Around     117
Chapter 12  Strings     121
The Basics     122
String Properties and Methods     124
    Accessing Individual Characters     124
    Combining (aka Concatenating) Strings     125
    Making Substrings out of Strings     126
    Splitting a String/split     128
    Finding Something Inside a String     129
    Upper and Lower Casing Strings     130
Chapter 13  When Primitives Behave Like Objects     133
Strings Aren’t the Only Problem     134
Let’s Pick on Strings Anyway     134
Why This Matters     137
Chapter 14  Arrays     139
Creating an Array     140
Accessing Array Values     141
Adding Items to Your Array     143
Removing Items from the Array     145
Finding Items in the Array     146
Merging Arrays     147
Chapter 15  Numbers     149
Using a Number     150
Operators     151
    Doing Simple Math     151
    Incrementing and Decrementing     152
Special Values—Infinity and NaN     153
    Infinity     153
    NaN     154
The Math Object     154
    The Constants     155
    Rounding Numbers     157
    Trigonometric Functions     158
    Powers and Square Roots     158
    Getting the Absolute Value     159
    Random Numbers        59
Chapter 16  A Deeper Look at Objects     161
Meet the Object     162
    Creating Objects     163
    Specifying Properties     167
Creating Custom Objects     169
The this Keyword     175
Chapter 17  Extending Built-in Objects     179
Say Hello to Prototype…Again—Sort of!     181
Extending Built-in Objects Is Controversial     185
    You Don’t Control the Built-in Object’s Future     186
    Some Functionality Should Not Be Extended or Overridden     186
Chapter 18  Booleans and the Stricter === and !== Operators     189
The Boolean Object     190
The Boolean Function     190
Strict Equality and Inequality Operators     192
Chapter 19  Null and Undefined     195
Null     196
Undefined     197
Chapter 20  Immediately Invoked Function Expressions     201
Writing a Simple IIFE     203
Writing an IIFE That Takes Arguments     204
When to Use an IIFE     205
    Avoiding Code Collisions     206
    Closures and Locking in State207
Making Things Private     213

PART III:  WORKING WITH THE DOM
Chapter 21  JS, The Browser, and The DOM     219

What HTML, CSS, and JavaScript Do     220
HTML Defines the Structure     220
Prettify My World, CSS!     222
It’s JavaScript Time!     223
Meet the Document Object Model     225
    The Window Object     227
    The Document Object     228
Chapter 22  Finding Elements in the DOM     231
Meet the querySelector Family     232
    querySelector     233
    querySelectorAll     233
It Really Is the CSS Selector Syntax     234
Chapter 23  Modifying DOM Elements     237
DOM Elements Are Objects—Sort of!     238
Let’s Actually Modify DOM Elements     240
    Changing an Element’s Text Value     242
    Attribute Values     242
Chapter 24  Styling Your Content     247
Why Would You Set Styles Using JavaScript?     248
    A Tale of Two Styling Approaches     248
    Setting the Style Directly     249
Adding and Removing Classes Using classList     250
    Adding Class Values     250
    Removing Class Values     251
    Toggling Class Values     251
    Checking Whether a Class Value Exists     252
    Going Further     252
Chapter 25  Traversing the DOM     255
Finding Your Way Around     256
    Dealing with Siblings and Parents     259
    Let’s Have Some Kids!259
Putting It All Together     261
    Checking Whether a Child Exists     261
    Accessing All the Child Elements     261
    Walking the DOM     262
Chapter 26  Creating and Removing DOM Elements     265
Creating Elements     266
Removing Elements     271
Cloning Elements     273
Chapter 27  In-Browser Developer Tools     279
Meet the Developer Tools     280
    Inspecting the DOM     282
    Debugging JavaScript     287
    Meet the Console     293
    Inspecting Objects     294
    Logging Messages     296

PART IV:  DEALING WITH EVENTS
Chapter  28 Events     299

What Are Events?     300
Events and JavaScript     302
    1. Listening for Events     302
    2. Reacting to Events     304
A Simple Example     305
The Event Arguments and the Event Type     307
Chapter 29  Event Bubbling and Capturing     311
Event Goes Down Event Goes Up     312
Meet the Phases     316
Who Cares?     319
Event, Interrupted     319
Chapter 30  Mouse Events     325
Meet the Mouse Events     326
    Clicking Once and Clicking Twice     326
    Mousing Over and Mousing Out     328
    The Very Click-like Mousing Down and Mousing Up Events     330
    The Event Heard Again…and Again…and Again!     331
    The Context Menu     332
The MouseEvent Properties     333
    The Global Mouse Position     333
    The Mouse Position Inside the Browser     334
    Detecting Which Button Was Clicked     335
Dealing with the Mouse Wheel     336
Chapter 31 Keyboard Events     339
Meet the Keyboard Events     340
Using These Events     341
The Keyboard Event Properties     342
Some Examples     343
    Checking That a Particular Key Was Pressed     343
    Doing Something When the Arrow Keys Are Pressed     344
    Detecting Multiple Key Presses     345
Chapter 32  Page Load Events and Other Stuff     349
The Things That Happen During Page Load     350
    Stage Numero Uno     351
    Stage Numero Dos     352
    Stage Numero Three     352
The DOMContentLoaded and load Events     353
Scripts and Their Location in the DOM     355
Script Elements—Async and Defer     358
    async     358
    defer     359
Chapter 33  Handling Events for Multiple Elements     363
How to Do All of This     365
    A Terrible Solution     366
    A Good Solution     367
    Putting It All Together     370
Chapter 34  Conclusion     373
Glossary     377
Index     381



Updates

Submit Errata

More Information

InformIT Promotional Mailings & Special Offers

I would like to receive exclusive offers and hear about products from InformIT and its family of brands. I can unsubscribe at any time.

Overview


Pearson Education, Inc., 221 River Street, Hoboken, New Jersey 07030, (Pearson) presents this site to provide information about products and services that can be purchased through this site.

This privacy notice provides an overview of our commitment to privacy and describes how we collect, protect, use and share personal information collected through this site. Please note that other Pearson websites and online products and services have their own separate privacy policies.

Collection and Use of Information


To conduct business and deliver products and services, Pearson collects and uses personal information in several ways in connection with this site, including:

Questions and Inquiries

For inquiries and questions, we collect the inquiry or question, together with name, contact details (email address, phone number and mailing address) and any other additional information voluntarily submitted to us through a Contact Us form or an email. We use this information to address the inquiry and respond to the question.

Online Store

For orders and purchases placed through our online store on this site, we collect order details, name, institution name and address (if applicable), email address, phone number, shipping and billing addresses, credit/debit card information, shipping options and any instructions. We use this information to complete transactions, fulfill orders, communicate with individuals placing orders or visiting the online store, and for related purposes.

Surveys

Pearson may offer opportunities to provide feedback or participate in surveys, including surveys evaluating Pearson products, services or sites. Participation is voluntary. Pearson collects information requested in the survey questions and uses the information to evaluate, support, maintain and improve products, services or sites, develop new products and services, conduct educational research and for other purposes specified in the survey.

Contests and Drawings

Occasionally, we may sponsor a contest or drawing. Participation is optional. Pearson collects name, contact information and other information specified on the entry form for the contest or drawing to conduct the contest or drawing. Pearson may collect additional personal information from the winners of a contest or drawing in order to award the prize and for tax reporting purposes, as required by law.

Newsletters

If you have elected to receive email newsletters or promotional mailings and special offers but want to unsubscribe, simply email information@informit.com.

Service Announcements

On rare occasions it is necessary to send out a strictly service related announcement. For instance, if our service is temporarily suspended for maintenance we might send users an email. Generally, users may not opt-out of these communications, though they can deactivate their account information. However, these communications are not promotional in nature.

Customer Service

We communicate with users on a regular basis to provide requested services and in regard to issues relating to their account we reply via email or phone in accordance with the users' wishes when a user submits their information through our Contact Us form.

Other Collection and Use of Information


Application and System Logs

Pearson automatically collects log data to help ensure the delivery, availability and security of this site. Log data may include technical information about how a user or visitor connected to this site, such as browser type, type of computer/device, operating system, internet service provider and IP address. We use this information for support purposes and to monitor the health of the site, identify problems, improve service, detect unauthorized access and fraudulent activity, prevent and respond to security incidents and appropriately scale computing resources.

Web Analytics

Pearson may use third party web trend analytical services, including Google Analytics, to collect visitor information, such as IP addresses, browser types, referring pages, pages visited and time spent on a particular site. While these analytical services collect and report information on an anonymous basis, they may use cookies to gather web trend information. The information gathered may enable Pearson (but not the third party web trend services) to link information with application and system log data. Pearson uses this information for system administration and to identify problems, improve service, detect unauthorized access and fraudulent activity, prevent and respond to security incidents, appropriately scale computing resources and otherwise support and deliver this site and its services.

Cookies and Related Technologies

This site uses cookies and similar technologies to personalize content, measure traffic patterns, control security, track use and access of information on this site, and provide interest-based messages and advertising. Users can manage and block the use of cookies through their browser. Disabling or blocking certain cookies may limit the functionality of this site.

Do Not Track

This site currently does not respond to Do Not Track signals.

Security


Pearson uses appropriate physical, administrative and technical security measures to protect personal information from unauthorized access, use and disclosure.

Children


This site is not directed to children under the age of 13.

Marketing


Pearson may send or direct marketing communications to users, provided that

  • Pearson will not use personal information collected or processed as a K-12 school service provider for the purpose of directed or targeted advertising.
  • Such marketing is consistent with applicable law and Pearson's legal obligations.
  • Pearson will not knowingly direct or send marketing communications to an individual who has expressed a preference not to receive marketing.
  • Where required by applicable law, express or implied consent to marketing exists and has not been withdrawn.

Pearson may provide personal information to a third party service provider on a restricted basis to provide marketing solely on behalf of Pearson or an affiliate or customer for whom Pearson is a service provider. Marketing preferences may be changed at any time.

Correcting/Updating Personal Information


If a user's personally identifiable information changes (such as your postal address or email address), we provide a way to correct or update that user's personal data provided to us. This can be done on the Account page. If a user no longer desires our service and desires to delete his or her account, please contact us at customer-service@informit.com and we will process the deletion of a user's account.

Choice/Opt-out


Users can always make an informed choice as to whether they should proceed with certain services offered by InformIT. If you choose to remove yourself from our mailing list(s) simply visit the following page and uncheck any communication you no longer want to receive: www.informit.com/u.aspx.

Sale of Personal Information


Pearson does not rent or sell personal information in exchange for any payment of money.

While Pearson does not sell personal information, as defined in Nevada law, Nevada residents may email a request for no sale of their personal information to NevadaDesignatedRequest@pearson.com.

Supplemental Privacy Statement for California Residents


California residents should read our Supplemental privacy statement for California residents in conjunction with this Privacy Notice. The Supplemental privacy statement for California residents explains Pearson's commitment to comply with California law and applies to personal information of California residents collected in connection with this site and the Services.

Sharing and Disclosure


Pearson may disclose personal information, as follows:

  • As required by law.
  • With the consent of the individual (or their parent, if the individual is a minor)
  • In response to a subpoena, court order or legal process, to the extent permitted or required by law
  • To protect the security and safety of individuals, data, assets and systems, consistent with applicable law
  • In connection the sale, joint venture or other transfer of some or all of its company or assets, subject to the provisions of this Privacy Notice
  • To investigate or address actual or suspected fraud or other illegal activities
  • To exercise its legal rights, including enforcement of the Terms of Use for this site or another contract
  • To affiliated Pearson companies and other companies and organizations who perform work for Pearson and are obligated to protect the privacy of personal information consistent with this Privacy Notice
  • To a school, organization, company or government agency, where Pearson collects or processes the personal information in a school setting or on behalf of such organization, company or government agency.

Links


This web site contains links to other sites. Please be aware that we are not responsible for the privacy practices of such other sites. We encourage our users to be aware when they leave our site and to read the privacy statements of each and every web site that collects Personal Information. This privacy statement applies solely to information collected by this web site.

Requests and Contact


Please contact us about this Privacy Notice or if you have any requests or questions relating to the privacy of your personal information.

Changes to this Privacy Notice


We may revise this Privacy Notice through an updated posting. We will identify the effective date of the revision in the posting. Often, updates are made to provide greater clarity or to comply with changes in regulatory requirements. If the updates involve material changes to the collection, protection, use or disclosure of Personal Information, Pearson will provide notice of the change through a conspicuous notice on this site or other appropriate way. Continued use of the site after the effective date of a posted revision evidences acceptance. Please contact us if you have questions or concerns about the Privacy Notice or any objection to any revisions.

Last Update: November 17, 2020