Home > Store

JavaScript Absolute Beginner's Guide, 2nd Edition

eBook

  • Your Price: $30.39
  • List Price: $37.99
  • 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.

Also available in other formats.

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

Description

  • Copyright 2020
  • Pages: 464
  • Edition: 2nd
  • eBook
  • ISBN-10: 0-13-620431-7
  • ISBN-13: 978-0-13-620431-2

Who knew how simple using JavaScript could be?
Make the most of JavaScripteven if you've never programmed anything before. JavaScript Absolute Beginner's Guide 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!
Here's a small sample of what you'll learn:
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 use 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
Learn how to perform common string operations
Use arrays to handle lists of data
Learn to create custom objects
Get up to speed on some of the big ES6 changes

Sample Content

Table of Contents

Introduction     1
Parlez-vous JavaScript?     2
Contacting Me/Getting Help     3
Chapter 1  Hello, World!     5
What Is JavaScript?     7
Hello, World!     8
    The HTML Document     8
Looking at the Code: Statements and Functions     11
PART I:  THE BASIC STUFF
Chapter 2  Values and Variables     15
Using Variables     16
More Variable Stuff     17
    Naming Variables     17
    More on Declaring and Initializing Variables     18
Chapter 3  Functions     21
What Is a Function?     23
A Simple Function     24
Creating a Function that Takes Arguments     28
Creating a Function that Returns Data     33
    The Return Keyword     33
    Exiting the Function Early     34
Chapter 4  Conditional Statements: If, Else, and Switch     37
The If / Else Statement     39
    Meet the Conditional Operators     41
    Creating More Complex Expressions     44
    Variations on the If / Else Statement     45
    Phew     47
Switch Statements     47
    Using a Switch Statement     47
    Similarity to an If/Else Statement     51
Deciding Which to Use     53
Chapter 5  Looping with For, While, and DoWhile!     55
The for Loop     57
    The Starting Point     61
    The Step     61
    The Condition (aka How Long to Keep Looping)     62
    Putting It All Together     62
Some for Loop Examples     63
    Breaking a Loop     63
    Skipping an Iteration     64
    Going Backwards     64
    You Don't Have to Use Numbers     65
    Oh, No He Didn't!     65
The Other Loops     66
    The while Loop     66
    The dowhile Loop     66
Chapter 6  Commenting Your CodeFTW!     69
What Are Comments?     70
    Single Line Comments     71
    Multi-Line Comments     72
Commenting Best Practices     73
Chapter 7  Timers     77
Delaying with setTimeout     78
    Looping with setInterval     79
    Animating Smoothly with requestAnimationFrame     80
Chapter 8  Variable Scope     83
Global Scope     84
Local Scope     86
Miscellaneous Scoping Shenanigans     87
Block Scoping     87
    How JavaScript Processes Variables     90
    Closures     92
Chapter 9  Closures     93
Functions within Functions     94
When the Inner Functions Aren't Self-Contained     98
Chapter 10  Where Should Your Code Live?     105
Approach #1: All the Code Lives in Your HTML Document     109
Approach #2: The Code Lives in a Separate File     110
    The JavaScript File     110
    Referencing the JavaScript File     111
SoWhich Approach to Use?     114
    Yes, My Code Will Be Used on Multiple Documents!     114
    No, My Code Is Used Only Once on a Single HTML Document!     116
PART II:  IT'S AN OBJECT-ORIENTED WORLD
Chapter 11  Console Logging Basics     119
Meet the Console     120
Displaying the Console     121
If You Want to Follow Along     124
Console Logging 101     125
    Meet the Log Method     125
    Going Beyond Predefined Text     127
    Displaying Warnings and Errors     128
Chapter 12  Of Pizza, Types, Primitives, and Objects     133
Let's First Talk About Pizza     134
From Pizza to JavaScript!     136
What Are Objects?     138
The Predefined Objects Roaming Around in JavaScript     140
Chapter 13  Arrays     143
Creating an Array     144
Accessing Array Values     145
Adding Items to Your Array     147
Removing Items from the Array     149
Finding Items in the Array     150
Merging Arrays     150
Mapping, Filtering, and Reducing Arrays     151
The Old School Way     151
Modifying Each Array Item with Map     152
Filtering Items     154
Getting One Value from an Array of Items     155
A Short Foray into Functional Programming     157
Chapter 14  Strings     159
The Basics     160
String Properties and Methods     161
    Accessing Individual Characters     161
    Combining (aka Concatenating) Strings     163
    Getting Substrings out of Strings     164
    Splitting a String/split     165
    Finding Something Inside a String     166
    Upper and Lower Casing Strings     168
Chapter 15  When Primitives Behave Like Objects     169
Strings Aren't the Only Problem     170
Let's Pick on Strings Anyway     170
Why This Matters     172
Chapter 16  Numbers     175
Using a Number     176
Operators     176
    Doing Simple Math     177
Incrementing and Decrementing     177
Hexadecimal and Octal Values     179
Special ValuesInfinity and NaN     180
    Infinity     180
    NaN     180
The Math Object     180
    The Constants     181
    Rounding Numbers     182
    Trigonometric Functions     183
    Powers and Square Roots     184
    Getting the Absolute Value     185
Random Numbers     185
Chapter 17  Getters and Setters     187
A Tale of Two Properties     188
Meet Getters and Setters     190
    Shout Generator     191
    Logging Activity     191
    Property Value Validation     192
Chapter 18  A Deeper Look at Objects     195
Meet the Object     196
    Creating Objects     197
    Adding Properties     197
    Removing Properties     200
    What Is Going on Behind the Scenes?     201
Creating Custom Objects     205
The this Keyword     209
Chapter 19  Extending Built-in Objects     213
Say Hello to prototypeagainSort of!     214
Extending Built-in Objects is Controversial     219
    You Don't Control the Built-in Object's Future     219
    Some Functionality Should Not Be Extended or Overridden     219
Chapter 20  Using Classes     221
The Class Syntax and Object Creation     222
    Creating an Object     222
    Meet the Constructor     224
    What Goes Inside the Class     226
Extending Objects     229
Chapter 21  Booleans and the Stricter === and !== Operators     237
The Boolean Object     238
The Boolean Function     238
Strict Equality and Inequality Operators     240
Chapter 22  Null and Undefined     243
Null     244
Undefined     244
PART III:  Working with the DOM
Chapter 23  All About JSON (aka JavaScript Object Notation)     247
What Is JSON?     248
Looking Inside a JSON Object     252
    Property Names     252
    The Values     253
Reading JSON Data     257
    Parsing JSON-looking Data into Actual JSON     259
Writing JSON Data?     259
Chapter 24  JS, the Browser, and the Dom     261
What HTML, CSS, and JavaScript Do     262
HTML Defines the Structure     262
Prettify My World, CSS!     264
It's JavaScript Time!     265
Meet the Document Object Model     267
    The Window Object     269
    The Document Object     269
Chapter 25  Finding Elements in the Dom     273
Meet the querySelector Family     274
    querySelector     275
    querySelectorAll     275
It Really Is the CSS Selector Syntax     276
Chapter 26  Modifying Dom Elements     279
DOM Elements Are ObjectsSort of!     280
Let's Actually Modify DOM Elements     282
    Changing an Element's Text Value     284
    Attribute Values     286
Chapter 27  Styling Our Content     289
Why Would We Set Styles Using JavaScript?     290
A Tale of Two Styling Approaches     290
    Setting the Style Directly     290
    Adding and Removing Classes Using JavaScript     292
Checking Whether a Class Value Exists     294
    Going Further     294
Chapter 28  Traversing the Dom     297
Finding Your Way Around     298
    Dealing with Siblings and Parents     301
    Let's Have Some Kids!     301
Putting It All Together     302
    Checking If A Child Exists     303
    Accessing All the Child Elements     303
    Walking the DOM     303
Chapter 29  Creating and Removing Dom Elements     305
Creating Elements     306
Removing Elements     314
Cloning Elements     315
Chapter 30  In-Browser Developer Tools     323
Meet the Developer Tools     324
    Inspecting the DOM     326
    Debugging JavaScript     331
    Meet the Console     337
    Inspecting Objects     338
    Logging Messages     340
PART IV:  DEALING WITH EVENTS
Chapter 31  Events     343
What Are Events?     344
Events and JavaScript     346
    1. Listening for Events     346
    2. Reacting to Events     348
A Simple Example     348
The Event Arguments and the Event Type     351
Chapter 32  Event Bubbling and Capturing     355
Event Goes Down Event Goes Up     356
Meet the Phases     361
Who Cares?     363
Event, Interrupted     364
Chapter 33  Mouse Events     367
Meet the Mouse Events     368
    Clicking Once and Clicking Twice     368
    Mousing Over and Mousing Out     370
    The Very Click-like Mousing Down and Mousing Up Events     372
    The Event Heard Againand Againand Again!     373
    The Context Menu     374
The MouseEvent Properties     375
    The Global Mouse Position     375
    The Mouse Position Inside the Browser     376
    Detecting Which Button Was Clicked     377
Dealing with the Mouse Wheel     378
Chapter 34  Keyboard Events     381
Meet the Keyboard Events     382
Using These Events     383
The Keyboard Event Properties     384
Some Examples     385
    Checking That a Particular Key Was Pressed     385
    Doing Something When the Arrow Keys Are Pressed     386
    Detecting Multiple Key Presses     386
Chapter 35  Page Load Events and Other Stuff     391
The Things That Happen During Page Load     392
    Stage Numero Uno     393
    Stage Numero Dos     393
    Stage Numero Three     394
The DOMContentLoaded and load Events     395
Scripts and Their Location in the DOM     397
Script ElementsAsync and Defer     400
    async     400
    defer     400
Chapter 36  Handling Events for Multiple Elements     405
How to Do All of This     407
    A Terrible Solution     408
    A Good Solution     409
    Putting It All Together     412
Chapter 37  Conclusion     415
Glossary     419
Index     423

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