0% found this document useful (0 votes)
8 views

Buy ebook JavaScript: A Beginner's Guide, Fifth Edition Pollock cheap price

Fifth

Uploaded by

pekindoody1s
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views

Buy ebook JavaScript: A Beginner's Guide, Fifth Edition Pollock cheap price

Fifth

Uploaded by

pekindoody1s
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 51

Download the Full Version of ebook for Fast Typing at ebookmass.

com

JavaScript: A Beginner's Guide, Fifth Edition


Pollock

https://ebookmass.com/product/javascript-a-beginners-guide-
fifth-edition-pollock/

OR CLICK BUTTON

DOWNLOAD NOW

Download More ebook Instantly Today - Get Yours Now at ebookmass.com


Recommended digital products (PDF, EPUB, MOBI) that
you can download immediately if you are interested.

JavaScript A Beginner's Guide Fifth Edition John Pollock

https://ebookmass.com/product/javascript-a-beginners-guide-fifth-
edition-john-pollock/

ebookmass.com

Javascript: Crash Course - The Complete Beginners Guide To


Learning JavaScript Programming In No Time! (Angularjs,
jQuery, JavaScript Visually) Nathaniel Hill
https://ebookmass.com/product/javascript-crash-course-the-complete-
beginners-guide-to-learning-javascript-programming-in-no-time-
angularjs-jquery-javascript-visually-nathaniel-hill/
ebookmass.com

The Norton Field Guide to Writing (Fifth Edition)

https://ebookmass.com/product/the-norton-field-guide-to-writing-fifth-
edition/

ebookmass.com

The Norton Field Guide to Writing: with Readings (Fifth


Edition) Fifth Edition – Ebook PDF Version

https://ebookmass.com/product/the-norton-field-guide-to-writing-with-
readings-fifth-edition-fifth-edition-ebook-pdf-version/

ebookmass.com
Creating Effective Teams: A Guide for Members and Leaders
(NULL) Fifth

https://ebookmass.com/product/creating-effective-teams-a-guide-for-
members-and-leaders-null-fifth/

ebookmass.com

Technical Analysis Explained, Fifth Edition : The


Successful Investoru2019s Guide

https://ebookmass.com/product/technical-analysis-explained-fifth-
edition-the-successful-investors-guide/

ebookmass.com

Learning Web Design: A Beginner’s Guide to HTML, CSS,


JavaScript, and Web Graphics 5th Edition, (Ebook PDF)

https://ebookmass.com/product/learning-web-design-a-beginners-guide-
to-html-css-javascript-and-web-graphics-5th-edition-ebook-pdf/

ebookmass.com

English File Beginner. Teacher's Guide (for speakers of


Spanish) Fourth Edition Christina Latham-Koenig

https://ebookmass.com/product/english-file-beginner-teachers-guide-
for-speakers-of-spanish-fourth-edition-christina-latham-koenig/

ebookmass.com

Writing Conversational Korean Book Two Katarina Pollock

https://ebookmass.com/product/writing-conversational-korean-book-two-
katarina-pollock/

ebookmass.com
BeginNew-Tight / JavaScript: A Beginner’s Guide, Fifth Edition / Pollock / 768-0 / Front Matter
Blind Folio: i

JavaScript
A Beginner’s Guide

Fifth Edition
John Pollock

New York Chicago San Francisco


Athens London Madrid Mexico City
Milan New Delhi Singapore
Sydney Toronto

00-FM.indd 1 17/09/19 5:33 PM


Copyright © 2020 by McGraw-Hill Education (Publisher). All rights reserved. Except as permitted under the United States
Copyright Act of 1976, no part of this publication may be reproduced or distributed in any form or by any means, or stored
in a database or retrieval system, without the prior written permission of the publisher, with the exception that the program
listings may be entered, stored, and executed in a computer system, but they may not be reproduced for publication.

ISBN: 978-1-26-045769-8
MHID: 1-26-045769-9

The material in this eBook also appears in the print version of this title: ISBN: 978-1-26-045768-1,
MHID: 1-26-045768-0.

eBook conversion by codeMantra


Version 1.0

All trademarks are trademarks of their respective owners. Rather than put a trademark symbol after every occurrence of a trade-
marked name, we use names in an editorial fashion only, and to the benefit of the trademark owner, with no intention of infringe-
ment of the trademark. Where such designations appear in this book, they have been printed with initial caps.

McGraw-Hill Education eBooks are available at special quantity discounts to use as premiums and sales promotions or for use in
corporate training programs. To contact a representative, please visit the Contact Us page at www.mhprofessional.com.

Oracle and Java are registered trademarks of Oracle Corporation and/or its affiliates. All other trademarks are the property of
their respective owners, and McGraw-Hill Education makes no claim of ownership by the mention of products that contain these
marks.

Screen displays of copyrighted Oracle software programs have been reproduced herein with the permission of Oracle Corpora-
tion and/or its affiliates.

Information has been obtained by Publisher from sources believed to be reliable. However, because of the possibility of human
or mechanical error by our sources, Publisher, or others, Publisher does not guarantee to the accuracy, adequacy, or completeness
of any information included in this work and is not responsible for any errors or omissions or the results obtained from the use
of such information.

TERMS OF USE

This is a copyrighted work and McGraw-Hill Education and its licensors reserve all rights in and to the work. Use of this work
is subject to these terms. Except as permitted under the Copyright Act of 1976 and the right to store and retrieve one copy of the
work, you may not decompile, disassemble, reverse engineer, reproduce, modify, create derivative works based upon, transmit,
distribute, disseminate, sell, publish or sublicense the work or any part of it without McGraw-Hill Education’s prior consent. You
may use the work for your own noncommercial and personal use; any other use of the work is strictly prohibited. Your right to
use the work may be terminated if you fail to comply with these terms.

THE WORK IS PROVIDED “AS IS.” McGRAW-HILL EDUCATION AND ITS LICENSORS MAKE NO GUARANTEES
OR WARRANTIES AS TO THE ACCURACY, ADEQUACY OR COMPLETENESS OF OR RESULTS TO BE OBTAINED
FROM USING THE WORK, INCLUDING ANY INFORMATION THAT CAN BE ACCESSED THROUGH THE WORK VIA
HYPERLINK OR OTHERWISE, AND EXPRESSLY DISCLAIM ANY WARRANTY, EXPRESS OR IMPLIED, INCLUD-
ING BUT NOT LIMITED TO IMPLIED WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR
PURPOSE. McGraw-Hill Education and its licensors do not warrant or guarantee that the functions contained in the work will
meet your requirements or that its operation will be uninterrupted or error free. Neither McGraw-Hill Education nor its licensors
shall be liable to you or anyone else for any inaccuracy, error or omission, regardless of cause, in the work or for any damages
resulting therefrom. McGraw-Hill Education has no responsibility for the content of any information accessed through the work.
Under no circumstances shall McGraw-Hill Education and/or its licensors be liable for any indirect, incidental, special, punitive,
consequential or similar damages that result from the use of or inability to use the work, even if any of them has been advised of
the possibility of such damages. This limitation of liability shall apply to any claim or cause whatsoever whether such claim or
cause arises in contract, tort or otherwise.
BeginNew-Tight / JavaScript: A Beginner’s Guide, Fifth Edition / Pollock / 768-0 / Front Matter
Blind Foli iii

To my wife, Heather, and children, Eva, Elizabeth, Elaine, and Evan,


Bruce and Joy Anderson, and Dr. J. D. and Linda Andrews

In memory of John and Betty Hopkins, James D. and


Livian Anderson, John William and Edith Hopkins,
Burley T. and Aline Price, “Doc” Flores, and Clifton Idom

00-FM.indd 3 17/09/19 5:33


BeginNew-Tight / JavaScript: A Beginner’s Guide, Fifth Edition / Pollock / 768-0 / Front Matter
Blind Foli iv

About the Author


John Pollock is employed as a software developer during
the day and works on Web sites and other projects during
the evening. You can find him on Twitter (@ScripttheWeb)
or LinkedIn (https://www.linkedin.com/in/john-pollock-
82a2b074). John holds a Bachelor of Arts in English from Sam
Houston State University and currently lives in New Waverly,
Texas with his wife, Heather, and children, Eva, Elizabeth,
Elaine, and Evan.

About the Technical Editor


Christie Sorenson is a senior software engineer at ZingChart.
She has worked on JavaScript-based systems since 1997 and
has been fascinated with the evolution of the language. She
has collaborated and been the technical editor on several
JavaScript and HTML books. She holds a Bachelor of Science
in Computer Science from University of California, San Diego,
and now lives in San Francisco with her husband, Luke, and
daughters, Ali and Keira.

00-FM.indd 4 17/09/19 5:33


BeginNew-Tight / JavaScript: A Beginner’s Guide, Fifth Edition / Pollock / 768-0 / Front Matter

Contents
ACKNOWLEDGMENTS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xvi
.
INTRODUCTION . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xvii
.
1 Introduction to JavaScript . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
.
What You Need to Know . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
.
Basic HTML and CSS Knowledge . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
.
Basic Text Editor and Web Browser Knowledge . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
.
Which Version? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
.
Client-Side and Server-Side Programming . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
.
Beginning with JavaScript . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
.
Prototype-Based . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
.
Interpreted Language . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
.
Numerous Environments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
.
Putting It All Together . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
.
Online Resources . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
.
Try This 1-1: Use JavaScript to Write Text . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
.
Chapter 1 Self Test ................................................................. 11
.
2 Placing JavaScript in an HTML File ..................................... 15
.
Using the HTML Script Tags ....................................................... 16
.
Identifying the Scripting Language . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
.
Calling External Scripts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
.
v

00-FM.indd 5 17/09/19 5:33


BeginNew-Tight / JavaScript: A Beginner’s Guide, Fifth Edition / Pollock / 768-0 / Front Matter

vi JavaScript: A Beginner’s Guide

Specifying when the Script Should Load . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18

.
Using <noscript></noscript> Tags . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18

.
Creating Your First Script . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20

.
Writing a “Hello World” Script ............................................... 20

.
Creating an HTML Document for the Script .................................. 21

.
Inserting the Script into the HTML Document . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21

.
Try This 2-1: Insert a Script into an HTML Document . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23

.
Using External JavaScript Files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24

.
Creating a JavaScript File . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24

.
Creating the HTML Files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24

.
Viewing the Pages in Your Browser . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26

.
Try This 2-2: Call an External Script from an HTML Document . . . . . . . . . . . . . . . . . . . . . 27

.
Using JavaScript Comments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28
.
Inserting Comments on One Line . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28
.
Adding Multiple-Line Comments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
29
Chapter 2 Self Test ................................................................. 30
.
3 Using Variables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33
Understanding Variables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34
.
Why Variables Are Useful .......................................................... 35
.
Variables as Placeholders for Unknown Values . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35
.
Variables as Time-Savers ..................................................... 35
.
Variables as Code Clarifiers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 36
.
Defining Variables for Your Scripts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 36
.
Declaring Variables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 36
.
Assigning Values to Variables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37
.
Naming Variables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 39
.
Understanding Data Types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41
.
Number ...................................................................... 41
.
String . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 42
.
Boolean . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 47
.
Null . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 47
.
Undefined . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 47
.
Symbol . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 48
.
Object . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 48
.
Try This 3-1: Declare Variables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 49
.
Using Variables in Scripts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 50
.
Making a Call to a Variable . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 50
.
Adding Variables to Text Strings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 50
.
Writing a Page of JavaScript . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 54
.
Creating the Framework . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 54
.
Defining the Variables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 54
.
Adding the Commands ....................................................... 55
.
Modifying the Page . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 56
.
00-FM.indd 6 17/09/19 5:33
BeginNew-Tight / JavaScript: A Beginner’s Guide, Fifth Edition / Pollock / 768-0 / Front Matter

Contents vii

Try This 3-2: Create an HTML Page with JavaScript . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 58

.
Chapter 3 Self Test ................................................................. 60

.
4 Using Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 63

.
What a Function Is . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 64

.
Why Functions Are Useful . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 64

.
Structuring Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 65

.
Declaring Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 65

.
Defining the Code for Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 66

.
Naming Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 67
.
Adding Arguments to Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 67

.
Adding Return Statements to Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 69

.
Calling Functions in Your Scripts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 71
.
Script Tags: Head Section or Body Section . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 72

.
Calling a Function from Another Function . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 75

.
Calling Functions with Arguments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
.
76
Calling Functions with Return Statements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 81
.
Other Ways to Define Functions .............................................. 82
.
Try This 4-1: Create an HTML Page with Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 86
.
Scope/Context Basics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 87
.
Global Context . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 87
.
Function Context . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 88
.
Block Context . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 89
.
Try This 4-2: Write Your Own Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 90
.
Chapter 4 Self Test ................................................................. 91
.
5 JavaScript Operators ..................................................... 95
.
Understanding the Operator Types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 96
.
Understanding Arithmetic Operators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 97
.
The Addition Operator (+) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 98
.
The Subtraction Operator (–) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 101
.
The Multiplication Operator (*) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 101
.
The Division Operator (/) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 102
.
The Modulus Operator (%) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 102
.
The Increment Operator (++) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 103
.
The Decrement Operator (– –) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 104
.
The Unary Plus Operator (+) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 105
.
The Unary Negation Operator (–) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 105
.
The Exponentiation Operator . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 106
.
Understanding Assignment Operators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 106
.
The Assignment Operator (=) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 107
.
The Add-and-Assign Operator (+=) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 107
.
The Subtract-and-Assign Operator (–=) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 108
.
The Multiply-and-Assign Operator (*=) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 109
.
The Divide-and-Assign Operator (/=) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 109
.
00-FM.indd 7 17/09/19 5:33
BeginNew-Tight / JavaScript: A Beginner’s Guide, Fifth Edition / Pollock / 768-0 / Front Matter

viii JavaScript: A Beginner’s Guide

The Modulus-and-Assign Operator (%=) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 109

.
The Exponent-and-Assign Operator (**=) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 109

.
Try This 5-1: Adjust a Variable Value . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 110

.
Understanding Comparison Operators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 111

.
The Is-Equal-To Operator (==) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 111

.
The Is-Not-Equal-To Operator (!=) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 113

.
The Strict Is-Equal-To Operator (===) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 114

.
The Strict Is-Not-Equal-To Operator (!==) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 114

.
The Is-Greater-Than Operator (>) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 114

.
The Is-Less-Than Operator (<) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 115

.
The Is-Greater-Than-or-Equal-To Operator (>=) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 116

.
The Is-Less-Than-or-Equal-To Operator (<=) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 116

.
Understanding Logical Operators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
.
117
The AND Operator (&&) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 117
.
The OR Operator (||) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 117
.
The NOT Operator (!) ........................................................ 118
.
The Bitwise Operators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 118
.
Special Operators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 119
.
Understanding Order of Operations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 120
.
Try This 5-2: True or False? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 121
.
Chapter 5 Self Test ................................................................. 123
.
6 Conditional Statements and Loops ....................................... 125
.
Defining Conditional Statements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 126
.
What Is a Conditional Statement? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 126
.
Why Conditional Statements Are Useful . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 127
.
Using Conditional Statements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 127
.
Using if/else Statements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 127
.
Using the switch Statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 137
.
Using the Conditional Operator . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 139
.
User Input from a Prompt . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 140
.
Try This 6-1: Work with User Input . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 143
.
Defining Loops . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 144
.
What Is a Loop? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 144
.
Why Loops Are Useful ....................................................... 144
.
Using Loops . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 145
.
for . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 145
.
while . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 154
.
do while . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 154
.
for in, for each in, and for of . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 156
.
Using break and continue . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 156
.
Try This 6-2: Work with for Loops and while Loops . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 158
.
Chapter 6 Self Test ................................................................. 160
.
00-FM.indd 8 17/09/19 5:33
BeginNew-Tight / JavaScript: A Beginner’s Guide, Fifth Edition / Pollock / 768-0 / Front Matter

Contents ix

7 JavaScript Arrays . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 163

.
What Is an Array? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 164

.
Why Arrays Are Useful . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 165

.
Defining and Accessing Arrays . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 165

.
Naming an Array . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 165

.
Defining an Array . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 165
Accessing an Array’s Elements ............................................... 167

.
Using the length Property and Loops . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 168

.
Changing Array Values and Changing the Length ............................. 169

.
Try This 7-1: Use Loops with Arrays . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 171

.
Array Properties and Methods ...................................................... 172
.
Properties . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 172
Methods . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 173
.
Nesting Arrays . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 189
.
Defining Nested Arrays . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 189
.
Loops and Nested Arrays . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 190
.
Try This 7-2: Nested Arrays Practice . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 192
.
Chapter 7 Self Test ................................................................. 193
.
8 Objects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 195
.
Defining Objects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 196
.
Creating Objects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 196
.
Naming . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 196
.
Single Objects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 197
.
Try This 8-1: Create a Computer Object . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 200
.
Object Structures . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 201
.
Constructor Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 201
.
Using Prototypes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 206
.
The class Keyword ........................................................... 209
.
Helpful Statements for Objects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 210
.
The for-in Loop . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 210
.
The with Statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 211
.
Try This 8-2: Practice with the Combination Constructor/Prototype Pattern . . . . . . . . . . 212
.
Understanding Predefined JavaScript Objects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 213
.
The Navigator Object . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 214
.
The History Object . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 216
.
Chapter 8 Self Test ................................................................. 218
.
9 The Document Object . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 221
.
Defining the Document Object . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 222
.
Using the Document Object Model . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 223
Using the Properties of the Document Object . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 223
Collections . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 225
.
The cookie Property . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 226
.
00-FM.indd 9 17/09/19 5:33
BeginNew-Tight / JavaScript: A Beginner’s Guide, Fifth Edition / Pollock / 768-0 / Front Matter

x JavaScript: A Beginner’s Guide

The dir Property . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 226

.
The lastModified Property . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 226

.
The referrer Property ......................................................... 227

.
The title Property . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 228

.
The URL Property . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 229

.
The URLUnencoded Property . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 229
Using the Methods of the Document Object . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 230

.
The get Methods for Elements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 230

.
The open() and close() Methods . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 235

.
The write() and writeln() Methods . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 237

.
Using DOM Nodes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 238
.
DOM Node Properties . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
.
238
DOM Node Methods ......................................................... 241
.
Try This 9-1: Add a DOM Node to the Document . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 246

.
Creating Dynamic Scripts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 247
.
Styles in JavaScript . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 247
.
Simple Event Handling . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 249
.
Coding a Dynamic Script . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 250
.
Try This 9-2: Try Out Property Changes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 252
Chapter 9 Self Test ................................................................. 253
.
10 Event Handlers ........................................................... 255
.
What Is an Event Handler? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 256
.
Why Event Handlers Are Useful . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 256
.
Understanding Event Handler Locations and Uses . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 257
.
Using an Event Handler in an HTML Element . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 257
.
Using an Event Handler in the Script Code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 259
.
Learning the Events . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 260
.
The Click Event . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 262
.
Focus and Blur Events . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 263
.
The Load and Unload Events . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 265
.
The Reset and Submit Events . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 268
.
The Mouse Events . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 269
.
The Keyboard Events . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 269
.
Try This 10-1: Focus and Blur . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 270
.
Other Ways to Register Events . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 272
.
The addEventListener() Method .............................................. 272
.
The attachEvent() Method . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 274
.
The Event Object . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 274
.
DOM and Internet Explorer: DOM Level 0 Registration . . . . . . . . . . . . . . . . . . . . . . . 274
.
Using event with Modern Event Registration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 275
.
Properties and Methods . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 276
.
Event Information . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 277
.
Try This 10-2: Using addEventListener() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 278
.
00-FM.indd 10 17/09/19 5:33
BeginNew-Tight / JavaScript: A Beginner’s Guide, Fifth Edition / Pollock / 768-0 / Front Matter

Contents xi

Creating Scripts Using Event Handlers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 278

.
Show Hidden Content ........................................................ 279

.
Change Content .............................................................. 280

.
Custom Events ............................................................... 284

.
Chapter 10 Self Test . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 286

.
11 Introduction to Node.js ................................................... 289

.
Introducing Node.js . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 290
.
Installing Node.js . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 291
.
Check for a Current Installation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 291

.
Install Node.js . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 292
.
Write a “Hello World” Script ................................................. 292

.
Using Node Modules . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 295
.
Using Native Node Modules . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
.
295
Asynchronous Execution ..................................................... 296
.
Non-Native Modules . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 298
.
Try This 11-1: Use a Custom Module . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 301
.
Installing a Database . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 301
.
Database Options . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 302
.
Install PostgreSQL . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 302
.
Create a Database Using pgAdmin . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 303
.
Try This 11-2: Test Some SQL Queries ............................................. 312
.
Creating a Web Server . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 313
.
Chapter 11 Self Test . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 315
.
12 Math, Number, and Date Objects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 317
.
Using the Math Object . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 318
.
What Is the Math Object? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 318
.
How the Math Object Is Useful . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 318
.
Properties . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 318
Methods . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 321
.
Try This 12-1: Display a Random Link on a Page . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 334
.
Understanding the Number Object . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 335
.
Properties . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 335
Methods . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 337
.
Using the Date Object . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 340
.
Properties and Methods . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 340
.
Methods That Get Values . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 342
.
Methods That Set Values . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 345
.
Other Methods . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 345
.
How About Some Date Scripts? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 346
.
Try This 12-2: Create a JavaScript Clock . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 350
.
Continuing Project . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 351
.
Getting to the Needed Data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 352
.
Running Some Calculations on the Results . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 353
.
Chapter 12 Self Test . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 355
.
00-FM.indd 11 17/09/19 5:33
BeginNew-Tight / JavaScript: A Beginner’s Guide, Fifth Edition / Pollock / 768-0 / Front Matter

xii JavaScript: A Beginner’s Guide

13 Handling Strings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 357

.
Introduction to the String Object . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 358

.
The String Object . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 358

.
The String Literal . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 359

.
What’s the Difference? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 359

.
Using the Properties and Methods of the String Object . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 360

.
The length Property . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 360

.
Methods of the String Object ....................................................... 360

.
Try This 13-1: Use indexOf() to Test an Address . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 370

.
Using Cookies . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 371
.
Setting a Cookie . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 372
.
Reading a Cookie . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 374
.
Try This 13-2: Remember a Name . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
.
376
Using Regular Expressions ......................................................... 377
.
Creating Regular Expressions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 377
.
Testing Strings Against Regular Expressions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 378

.
Adding Flags . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 379
.
Creating Powerful Patterns . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 380
.
Grouping Expressions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 384
.
The replace(), match(), matchAll(), and search() Methods . . . . . . . . . . . . . . . . . . . . . 384

.
More Information . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 387
.
Continuing Project . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 387
.
Chapter 13 Self Test . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 389
.
14 Browser-Based JavaScript ................................................ 391
.
Window: The Global Object . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 392
.
Using the Properties of the Window Object . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 393
.
The closed Property . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 394
The frames Property . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 395
.
The innerWidth and innerHeight Properties . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 395
.
The length Property . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 395
.
The location Property . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 395
.
The name Property ........................................................... 396
.
The opener Property . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 396
.
The parent, self, and top Properties . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 397
.
The status and defaultStatus Properties . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 397
.
Try This 14-1: Use the location and innerWidth Properties .......................... 398
.
Using the Methods of the Window Object . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 399
.
The alert(), prompt(), and confirm() Methods . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 400
The print() Method . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 401
.
The setInterval() and clearInterval() Methods . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 403
The setTimeout() and clearTimeout() Methods . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 404
.
Try This 14-2: Use the setTimeout() and confirm() Methods . . . . . . . . . . . . . . . . . . . . . . . . . 406
.
00-FM.indd 12 17/09/19 5:33
BeginNew-Tight / JavaScript: A Beginner’s Guide, Fifth Edition / Pollock / 768-0 / Front Matter

Contents xiii

The Main Window and New Windows . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 407

.
The Tale of Pop-up Windows ................................................. 407

.
Opening New Windows . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 408

.
Closing New Windows . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 411

.
Moving, Resizing, and Scrolling New Windows . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 412

.
The resizeBy() and resizeTo() Methods ....................................... 416

.
The scrollBy() and ScrollTo() Methods . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 418

.
Working with Images . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 418
.
Rollovers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 418
.
JavaScript and Frames . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
.
420
Purpose of Frames . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 420
.
Accessing Frames . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 420
.
Breaking Out of Frames ...................................................... 423
.
Using iFrames . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 424
.
Chapter 14 Self Test . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 424
.
15 JavaScript Forms and Data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 427
.
Accessing Forms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 428
.
Using the forms Array . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 428
.
Using an ID .................................................................. 431
.
Using the Properties and Methods of the Form Object . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 433
.
Properties . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 433
Methods . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 436
.
Ensuring the Accessibility of Forms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 438
.
Using Proper Element and Label Order ....................................... 438
.
Using <label></label> Tags . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 438
.
Using <fieldset></fieldset> Tags . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 439
.
Not Assuming Client-Side Scripting .......................................... 439
.
Validation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 440
.
Simple Validation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 440
.
Techniques . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 441
.
Check Boxes and Radio Buttons . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 442
.
Try This 15-1: Request a Number . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 445
.
HTML5 and Forms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 446
.
New Elements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 446
.
New Input Types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 450
.
New Attributes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 452
.
HTML5 Form Validation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 452
.
Try This 15-2: Validate a Phone Number with HTML5 or JavaScript ................ 455
.
AJAX and JSON . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 456
.
AJAX ........................................................................ 456
.
JSON . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 462
.
Chapter 15 Self Test . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 465
.
00-FM.indd 13 17/09/19 5:33
BeginNew-Tight / JavaScript: A Beginner’s Guide, Fifth Edition / Pollock / 768-0 / Front Matter

xiv JavaScript: A Beginner’s Guide

16 Further Browser-Based JavaScript . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 469

.
Using jQuery . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 470

.
Obtaining jQuery . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 470

.
Getting Started: document.ready() ............................................ 471

.
Using Selectors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 471

.
Altering Classes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 473

.
Methods for Effects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 475

.
Further Reading . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 477
.
Try This 16-1: Use jQuery to Create Effects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 477

.
Debugging Scripts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 479
.
Types of Errors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 479
.
Using the Console . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 482
.
Using a Lint Tool . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 483
.
Browser Developer Tools . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 484
.
JavaScript and Accessibility . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 485
.
Separate Content from Presentation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
486
Enhancing Content ........................................................... 488
.
Try This 16-2: Make This Code Accessible . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 488
.
JavaScript Security . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 489
.
Page Protection . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 490
.
JavaScript and APIs from HTML ................................................... 492
.
The <canvas> Element . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 492
.
Drag and Drop . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 498
.
Try This 16-3: Drag and Drop . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 502
.
Node.js App Completion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 503
.
Update the Node.js Code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 503
Update the Front-end Code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 504
.
Need Help? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 508
.
Chapter 16 Self Test . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 509
.
A Answers to Self Tests . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 511
.
Chapter 1: Introduction to JavaScript . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 512
.
Chapter 2: Placing JavaScript in an HTML File . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 512
.
Chapter 3: Using Variables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 513
.
Chapter 4: Using Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 513
.
Chapter 5: JavaScript Operators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 514
.
Chapter 6: Conditional Statements and Loops . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 515
.
Chapter 7: JavaScript Arrays . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 515
.
Chapter 8: Objects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 516
.
Chapter 9: The Document Object . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 517
.
00-FM.indd 14 17/09/19 5:33
Discovering Diverse Content Through
Random Scribd Documents
in a revery of delight. An occasional clearing, containing a cottage
with its rustic appendages, opened the sunshine into our path, and
made the wood cheerful by this pleasant contrast. When at length we
emerged from this gloomy region into the brightness and
cheerfulness of the open country, I still dwelt upon the quiet
grandeur of its solitudes, and have never forgotten the impressions I
had received from them, nor the passionate interest awakened in me
before my journey.
About thirty years afterwards I revisited this wood, and traversed
the greater part of it, accompanied by an old friend of the generation
that had passed before me. From him I learned that the original
growth of timber had been mostly felled, and a second growth of
inferior height and dimensions occupied its place. He pointed out to
me how the whole character of the wood was changed by the simple
act of felling the primitive trees. The ground was not so wet as
formerly; the standing waters did not occupy so wide a space; the
forest contained more openings, the barren elevations not having
been supplied with a new growth of trees. In the place of them were a
few scrub oaks, some whortleberry-bushes, and other native shrubs;
the trees were smaller, and there was a greater predominance of
pitch-pine in all the more sandy parts of the tract, and numerous
white birches had sprung up among them.
“Such is the change,” he remarked, “which is gradually taking
place over the whole continent.” He seemed to regret this change,
and thought the progress of the civilized arts, though it rendered
necessary the clearing of the greater part of the wooded country,
ought not to be attended with such universal devastation. Some
spacious wood ought to remain, in every region, in which the wild
animals would be protected, and where we might view the grounds
as they appeared when the wild Indian was lord of this continent.
Even at that time I found some acres of forest which had been
unmolested still retaining those grand, wild, and rugged features that
entitled the region to the poetic name of Dark Plains.
THE RED MAPLE.

Not dainty of its soil, but thriving equally well in a bog or upon a
fertile river-bank, by the side of a stream or upon a dry eminence;
coming forth in the spring, like morning in the east, arrayed in
crimson and purple; bearing itself not proudly, but gracefully, in
modest green, among the more stately trees in summer; and, ere it
bids adieu to the season, stepping forth in robes of gold, vermilion,
crimson, and variegated scarlet, stands the queen of the American
forest, the pride of all eyes and the delight of every picturesque
observer of nature,—the Red Maple. There are but few trees that
surpass it in general beauty of form and proportion, and in the
variety and splendor of its autumnal tints it is not equalled by any
known tree. Without this species, the American forest would hardly
be distinguished from that of Europe by any superiority of tinting. It
stands among the occupants of the forest like Venus among the
planets, the brightest in the midst of brightness, and the most
beautiful in a constellation of beauty.
The Red Maple is a tree of second magnitude, very comely at all
periods of its growth, producing many branches, forming a
somewhat pyramidal top while young, but expanding into a round
head as it grows old. It is very evenly subdivided, the central shaft
seldom being distinguished above the lower junction of its principal
branches. The leaves are palmate, of rather a pale green, and the
spray, though neat and elegant, does not equal that of the lime or the
birch. We associate this tree with the valleys and lowlands, but a wet
soil is not necessary for its prosperity. Some of the finest single trees
I have known were standing upon a dry soil; but a forest of them is
always located in a swamp.
The Red Maple is one of the most common trees in the southern
parts of New England, and it occupies a very wide geographical
range. In the North it first appears in the latitude of Quebec. It seems
to avoid the company of the rock maple, and forms no large
assemblages above the northern boundary of Massachusetts, below
which the kindred species becomes rare in New England. The Red
Maple is abundant in all the Atlantic States, as far as Florida, and
there is no other tree that occupies so large a proportion of the wet
lands in the Middle States. According to Michaux, it is the last tree
which is found in swamps, as we approach the boundary of
vegetation.
Preference is generally given to the other two species for planting
by waysides and in pleasure-grounds in Massachusetts, because they
are more luxuriant in their growth. Perhaps they are chosen for the
sake of variety, being less common in the woods of this State than the
Red Maple; and being planted from nurseries, and costly, they are
found chiefly in dressed grounds. But the Red Maple is far more
interesting and beautiful than any other species, and its lighter
foliage, more airy habit, and more delicate spray bring it into better
harmony with wild and rude scenery, as the paler and less luxuriant
wild flowers better adorn a wood-path than the more showy denizens
of the garden. The Red Maple bears a profusion of crimson flowers in
the spring, and from them it derives its name. When the flowers have
dropped their petals, the keys, or fruit-pods, that succeed them,
retain the same crimson hue for some days, gradually fading into
brown as they mature.
THE WHITE BIRCH.

On the sandy plains of many parts of New England, some of the


most prominent objects are coppices of slender White Birch trees,
intermingled with pitch-pine. These trees are seldom more than four
or five inches in diameter, rising to the height of about twenty feet,
with a grayish-white trunk, and, as may be observed in winter, a
dense and dark-colored spray. This species is called Poplar Birch,
from the tremulous habit of the foliage, but is never assembled in
large forest groups. Like the alder, it is employed by Nature for the
shading of her living pictures, and for producing those gradations
which are the charm of spontaneous wood-scenery. In all the
Northern States, a pitch-pine wood is generally fringed with White
Birches, and outside of them is a still more humble growth of hazels,
cornels, and vacciniums, uniting them imperceptibly with the
herbage of the plain.
The White Birch is remarkable for its elegance. It seldom divides
the main stem, which extends to the summit of the tree, giving out
from all parts numerous slender branches, forming a very neat and
beautiful spray, of a dark chocolate-color, contrasting finely with the
whiteness of the trunk. This tree, when growing as a standard, has
more of a pyramidal shape than in a wood; but it does not attain in
this country the magnitude of the same species in Europe. The
durability of the bark of the White Birch is said to be unsurpassed by
that of any other vegetable substance. Selby records a fact related by
Du Hamel, which is remarkable. In the ruins of Dworotrkoi, in
Siberia, a piece of birch wood was found changed into stone, while
the outer bark, white and shining, remained in its natural state.
So many of the most delightful scenes of nature are in my own
mind allied with the different birches, that there is not one that does
not immediately call up some charming scenery and impress my
mind with pleasant memories. He who in his early days was a
rambler in the woods is familiar with the White Birch trees. They
have shaded him in his sylvan researches and his solitary musings,
his social walks in quest of flowers with the sex for whom the flowers
seemed to be created, or with his male companions in pursuit of
game. When journeying, these graceful trees, in company with the
fragrant pitch-pines, have offered him their flickering shade, and
along the sandy plains have defended him from the scorching heat of
the sun, and spread a leafy canopy over his rustic path. In the sultry
heat of summer noonday, I have often followed the course of some
humble cart-path through their tangled undergrowth, gathering wild
fruits from bush and bramble, or watching the singing birds that
nestled in their boughs and blended their wild notes with the sound
of the green rustling leaves.
All the birches are graceful trees. Their branches are finely divided,
like those of the elm and the lime, and many of them incline to a
drooping habit. There is a remarkable airiness in their slender
feathery spray, rendered still more lively in the White Birch by its
small tremulous leaves. This species is found in the highest latitude
in which any tree can live. It is the last deciduous tree in the northern
boundaries of vegetation in America and Europe, before we reach the
Arctic Circle, and the last that appears when we ascend high
mountains, occupying the belt just below the line of perpetual snow.
It is worthy of notice that the small White Birch in this country,
though considered identical with the White Birch of Europe, is
greatly inferior to it in size. In America, however, the white canoe
birch, a very similar species, equally surpasses the European White
Birch. It seems as if the thrifty habit of the canoe birch had some
mysterious influence in dwarfing the other species in America.
THE CANOE BIRCH.
Some of the most beautiful assemblages of wood in high latitudes
on this continent consist of the Canoe Birch. It is seen in
Massachusetts and Connecticut only in occasional groups; but in the
States of Maine and New Hampshire, on the sandy river-banks and
diluvial plains, it forms woods of great extent and unrivalled beauty.
With their tall shafts resembling pillars of polished marble,
supporting a canopy of bright green foliage, they form one of the
picturesque attractions of a Northern tour. Nature indicates the
native habitat of this noble tree by causing its exterior to display the
whiteness of snow. The foliage of the Canoe Birch is of a very bright
green, and exceeds that of all the family in the depth of its golden
tints in autumn. We never see in the foliage of the birches any of that
glaucous or pea-green color so common in the maples. The leaves of
the Canoe Birch deviate from the ovate form and approach the heart
shape. Its bark is almost purely white, and attracts the attention of
every visitor of the woods. The clean white shafts of a Canoe Birch
wood, towering upward among the other trees of the forest, present a
scene with which nothing else is comparable. The uses which have
been made of the bark of this tree are so numerous and so familiar to
all that it would be idle to enumerate them. Indeed, it would be
difficult to estimate its importance to the aboriginal inhabitants of
America.
RELATIONS OF TREES TO BIRDS AND
INSECTS.

“My neighbors,” said my philosophic friend, “are the cause of more


than half the injury my crops receive from caterpillars and other
insects. They will not allow the birds a harbor of wood and shrubbery
upon their own grounds, and they shoot those which I endeavor to
entice by offering them a shelter in my farm. It is strange they cannot
understand the mischievous character of their operations of
smoothing and grubbing. That little rising ground you see before
you, covered with trees and shrubs, is hardly more than a bare rock.
It occupies about an eighth of an acre; but no other possible use
could be made of it, except as a quarry. The little grove, or coppice,
that stands upon it, is the most beautiful object in sight from my
house. I have never allowed it to be disturbed or frequented by social
assemblages. I keep it sacred for the use of the birds, and it is a
perfect aviary. The birds that feed upon the destructive insects that
infest my grounds are raised in that temple of the gods, which is
watered by numerous little springs that ooze from the crevices of the
rock. While they are rearing their young, all species, even if they live
exclusively upon seeds after they have left their nest, feed their
offspring upon larvæ, which they collect from the nearest ground
that affords them a supply. Hence I consider that bare rock, with its
trees and shrubbery, the most profitable division of my farm, from
the shelter it affords the birds, which are in an important sense my
most profitable stock.”
I have often thought of my neighbor’s remarks, especially when I
have observed the diligence of our farmers in destroying upon their
grounds every acceptable harbor for the birds. When we are
traversing a wood, if we discover an apple-tree growing in a little
clearing or open space, we find it invariably exempt from the ravages
of the common apple-borer. The same exemption is observed in
those fruit-trees that stand very near a wild wood, or any wood
containing a spontaneous undergrowth. The explanation of this fact
is that the wood affords a harbor to the birds that destroy these
insects in all their forms. Orchards and gardens, on the contrary,
which are located at any considerable distance from a wood, have not
this security. Robins, it is true, are very abundant in orchards, which
are their breeding-places; but robins, though the most useful birds
that are known to exist, take all their food from the ground. They
destroy vast quantities of cutworms and chrysalids buried in the soil,
but they take no part of their insect food from the trees. The birds
that perform this work are the sylvias, woodpeckers, creepers, and
other species that live only in woods and thickets. Hence an orchard
that is nearly surrounded by a wild wood of much extent is not badly
infested by borers and other injurious insects.
All species of insects multiply in cultivated grounds, while the
birds, with a few exceptions, that feed upon them, can find a nursery
and protection only in the woods. “The locust,” says George P.
Marsh, “which ravages the East with its voracious armies, is bred in
vast open plains, which admit the full heat of the sun to hasten the
hatching of the eggs, gather no moisture to destroy them, and harbor
no bird to feed upon their larvæ. It is only since the felling of the
forests of Asia Minor and Cyrene that the locust has become so
fearfully destructive in those countries; and the grasshopper, which
now threatens to be almost as great a pest to the agriculture of North
American soils, breeds in seriously injurious numbers only where a
wide extent of surface is bare of woods.”
Some men destroy trees and shrubbery in their borders, because
they are supposed to harbor insects. But if this be true, it is because
they are not sufficient in extent to shelter the birds that feed upon
them. The insects that multiply upon our lands deposit their eggs
some in the soil, some on the branches of trees and upon fences and
buildings. They are nowise dependent on a wild growth of wood and
shrubbery. These pests of agriculture need nothing better than the
under edge of a clapboard or a shingle whereon to suspend their
cocoons or lay their eggs. So minute are the objects that will afford
them all the conveniences they need, when hatching and when
passing through all their transformations, till they become perfect
insects, that no artifice or industry of man can deprive them of their
nurseries, or appreciably lessen their numbers. All inventions and
appliances used to rid the trees and grounds of these pests never
destroyed more than one in a million of their whole number. It is not
in the power of man, with all his science, unassisted by birds, to
prevent the multiplication of insects from being the cause of his own
annihilation. But the farmer, when he destroys the border shrubbery
in his fields and the coppice and wood on his hills, exterminates the
birds by hosts, while the mischievous boy with his gun destroys only
a few individuals. The clipped hedge-row, which is often substituted
for a border of wild shrubbery, may assist in breeding insects; but the
birds never build their nests in a hedge-row, unless it be a long-
neglected one.
I have in another essay spoken of the scarcity of birds and other
animals in the primitive forest. They are not numerous there,
because the forest would yield them only a scanty subsistence. The
forest border is their nursery and their shelter, but their best feeding-
places are the cultivated grounds. There is not a single species whose
means of subsistence are not increased by the clearing of the forest
and the cultivation of the land; but they require a certain proportion
of wild wood for their habitation. Very few species build their nests
in the trees and shrubbery of our gardens, unless they are near a
wood. In that case the catbird often nestles in the garden, that during
the rearing of its young it may be near the grounds that produce
larvæ. Most of the woodpeckers, the sylvias, and the small thrushes,
including some of our most valuable birds, cannot rear their young
except in a wild wood. Yet all these, solitary as they are in their
habits, increase under favorable circumstances with the
multiplication of insects consequent upon the culture of the soil. It
may be affirmed as an indisputable truth, that if their increase were
not checked by the sporting habits of men and boys, and the clearing
and grubbing habits of “model farmers,” birds of every species would
increase in the same ratio with the multiplication of their insect food,
and proportionally diminish their ravages.
THE BLACK OR CHERRY BIRCH.

The epithets “black,” “white,” “red,” and “yellow,” which are so


commonly misapplied to certain trees for specific distinction,—a
misapplication very remarkable with reference to the poplar,—are
very well applied to the different species of birch, and serve as
intelligible marks of identity. The Black Birch, for example, is clothed
with a dark-colored bark, which comes nearer a pure black than any
other color. No person would dispute the color of the white birches;
that of the yellow birch, though not pure, would never be mistaken
for anything but yellow; and the bark of the red birch, though nearly
white, is so thoroughly stained with red as to demonstrate the
propriety of its name.
The Black Birch is also named the Cherry Birch, from the
resemblance of the tree to the American black cherry. Its inner bark
has the flavor of checkerberry, and its wood some of the colors of
mahogany; and it has received names corresponding with these
characters, such as Sweet Birch and Mahogany Birch, and was
formerly a favorite material for cabinet furniture. The bark of this
species and of the yellow birch has very little of that leathery or
papyraceous quality which is so remarkable in that of the white
birches. This species does not extend so far north as the others, but
has a wider geographical range in and below the latitude of New
England.
The Black Birch puts forth its flowers very early in the year, of a
deep yellow and purple and sensibly fragrant. The foliage also
appears early. The leaves are finely serrate, oval, with conspicuous
veins, turning yellow in the autumn. Not one of the birches ever
shows a tint approaching to red or purple in its foliage. The Black
Birch delights in moist grounds, and commonly occupies a stand on
mountain slopes and on the banks of rivers. When growing singly on
a plain, or in an open space, it takes a hemispherical shape, with its
terminal and lower branches drooping to some extent like those of
the elm. This tree is conspicuous on craggy precipices, among the
mountains, where it extends its roots into the crevices of the rocks,
and spreads its branches over chasms and hollows. On these sites it
displays a variety of picturesque forms, corresponding with the
rudeness and the wildness of the scenery around it. Nature has
furnished this tree with a chaffy or winged seed, which is soon wafted
and sown by the winds upon mountain-sides and among inaccessible
rocks, where the soil collected in thin fissures supplies it with
sustenance.
THE YELLOW BIRCH.
The Yellow Birch, named excelsa by botanists, from its superior
height, is perhaps the most beautiful of the genus. Its branches are
extremely numerous, long and slender, corresponding with the
superior length of its trunk, and they are prone, like those of the elm,
to equality in size, and to divergency from nearly a common centre.
Indeed, where this tree has grown as an isolated standard, it
commonly displays a very symmetrical head, differing in form from a
perfect elm only by less inclination to droop. The leaves of this
species have much of the same quality which I have remarked as
peculiar to the beech, every leaf standing erect upon its stem. The
flexible appearance of the tree is derived entirely from its slender
flowing branches.
The Yellow Birch is very abundant in Maine and New Brunswick,
and formerly constituted the greater part of the wood which was
brought into Massachusetts for fuel. Many of the logs were of
immense size before the primitive forest was removed. At the present
day we seldom find one more than eighteen inches in diameter,
though many slender individuals still occupy our woods. It delights
in cold, damp soils, and I have seen the finest standards near springs
on an open hillside. The Yellow Birch derives its name from the
golden hue of the bark that covers the trunk and larger limbs. This
silken bark, which is rolled into multitudes of soft ringlets, is peculiar
to this tree.
THE RED BIRCH.
The Red Birch is a rare species, and but very little known. By
careless observers it might be mistaken for a white birch, the redness
of its bark seeming only a departure from its usual type. The only
trees of this species I have seen in Massachusetts were in Andover, in
a swamp through which the Shawsheen River flows. If you would
behold this tree to the best advantage, you must follow the streams
that glide along the level woodlands which are inundated a part of
the year. There it may be seen, like some pilgrim bending
worshipfully over the stream, by whose beneficent waters it is
sustained in beauty and health. Its picturesque attractions, arising
from the great variety of its outlines and the peculiar wreathing of its
foliage around the stem, are not surpassed by those of the willow,
that delights in similar places. The reddish whiteness of the bark and
wood has given the name to this tree. It is a tall, bushy tree of rapid
growth, rolling up its bark in coarse ringlets, which are whitish with a
stain of crimson.
THE INDIAN SUMMER.

When November arrives, leading along with it the short days and
the darkness of winter, it opens the windows of the deep woods,
pervaded all summer by a sort of artificial twilight. The general
denuded state of the forest admits the sunshine into its interior, and
brightens it with a cheerfulness exceeding that of any other season.
Some light-tinted leaves still remain upon the trees which have been
screened by their situation from the frost and the wind, and many an
interesting object is exposed to view which was concealed by the
foliage in summer. A few asters and gentians still linger in some
protected nook, and the chickadees and hemp-birds make the wood
lively by their garrulity and their motions. The ground is covered
with red, brown, and yellow leaves, making a pleasant carpet for our
feet, and increasing all the pleasures of a woodland ramble.
After the fall of the leaf is completed, then, according to tradition,
comes the Indian Summer,—a fruitful theme both for poets and
philosophical writers, but of which no one knows anything from
experience. It may, after all, be only a myth, like the halcyon days of
the ancients, the offspring of a tradition that originated with certain
customs of the Indian, and which occasional days of fine weather in
the autumn have served to perpetuate. It is certain that we have now
in the Eastern States no regular coming of this delightful term of
mildness and serenity, this smiling interruption of the melancholy
days of autumn. We are greeted occasionally by two or three days
resembling it after the first cool weather of October, and these short
visits are in some years repeated several times. But a true Indian
Summer, attended with all the peculiar phenomena described by
some of our early writers both in prose and verse, rarely
accompanies a modern autumn. It has fled from our land before the
progress of civilization; it has departed with the primitive forest. I
will, however, for the present, set aside all my conjectures of its
mythical character, and treat it as a matter of fact.
The Indian Summer, if such a season was ever known, was a
phenomenon produced by some unexplained circumstances
attending the universal wooded state of the country that existed for
many years after its settlement. According to the most apparently
authentic accounts, it did not arrive until November, nor until a
series of hard frosts had destroyed all the leaves of the forest. It then
appeared regularly every year. At the present time people know so
little about it that they cannot name the period of the autumn when,
if it were not a thing of the past, it should be expected. Will the
disappearance of this phenomenon admit of a philosophic
explanation? Let us consider some of its probable causes, and the
effects of the changes which have taken place in our land.
It has been observed that a meadow covered with luxuriant grass
and other herbage cools the atmosphere that rests upon it much
more rapidly than a similar meadow covered with a scanty herbage.
The moisture exhaled into the air by vegetable perspiration is greater
than from any other natural surface; and as the radiation of heat is
rapid in proportion to the moist condition of the atmosphere, the
cooling process over a grassy meadow is vastly greater than over a
similar ground bare of vegetation. A wood, in like manner, by
exhaling through its foliage the moisture it draws from the earth,
cools the atmosphere in proportion to the amount of its foliage, while
at the same time it shades the ground from the sun. Anything that
should check this vegetable perspiration would in the same ratio
preserve the heat of the atmosphere by diminishing the radiation of
heat that takes place more slowly in dry than in moist air.
This is precisely what happens soon after the first severe frosts of
November, when the whole extent of the forest over thousands of
miles is laid bare in the brief space of two or three days. There is a
sudden and universal diminution of the moisture that was given out
from the leaves of trees and other plants before the frost had
destroyed them; for the evaporation caused by the drying of fallen
leaves and herbage is comparatively slight, and ceases after a few
hours’ exposure to the sun. The atmosphere being dry, and the
radiation of heat proportionally small in quantity, all these
circumstances, if no unusual atmospheric disturbances occur from
any other hidden cause, unite in producing a sudden and universal
accumulation of heat. The warm period that follows is the Indian
Summer.
A writer in “Silliman’s Journal” of 1833, who advances a very
different theory to explain this phenomenon, makes a statement that
favors my view: “It appears to us that the existence and duration of
the Indian Summer in this country has an important connection with
the extensive forests and uncultivated lands peculiar to America. And
it is worthy of remark, that, according to the recollection of the oldest
of our inhabitants, its former duration was often three or four weeks;
whereas its present continuance is short and uncertain, seldom
exceeding ten or fifteen days. It appears also that this decline has
been somewhat regular, keeping pace with, and evidently influenced
by, the gradual uncovering of the country.”
It is surprising that the writer, after making these observations,
should resort to some unintelligible reasoning about the trade-winds,
and certain assumed electric phenomena, to account for the Indian
Summer. I can easily believe that before the encroachments upon the
American forest were very extensive, this halcyon period of autumn
may have occurred every year with great regularity. But since the
clearing is almost universal, these conditions have been entirely
changed. During the primitive state of the forest, its sudden
denudation produced a more complete revolution on the face of the
country than could possibly happen at the present time. The clearing
of the woods has also cast down the barriers that impeded the
circulation of the winds; at present these winds, sweeping freely over
the continent, would counteract any influences, whatever they might
be, that would produce an Indian Summer in any locality.
The true Indian Summer was a period of very mild weather, lasting
from ten to fifteen days, and accompanied neither by wind nor rain.
It has been incorrectly described by certain writers as attended with
fog. The sky, though somewhat dim, was not obscured by vapor, but
by a sort of ruddy haze, that veiled the prospect, as it often will
during a series of warm, still days happening at any season. I draw
my inferences from what I have reason to consider the most
authentic accounts. The air was dry; and it could not have been
otherwise. If it were moist, the increased radiation would soon
dissipate the heat and put an end to the Indian Summer, which was
never known to survive a copious and extensive fall of rain. The
atmosphere was described as being obscured by smoke, rather than
vapor, and this was most apparent in the latter part of the day. This
smoky atmosphere has led some writers to suppose the whole
phenomenon to be caused by fires in the woods.
According to tradition, no part of the year was more delightful
than this short period. Those accounts, however, that extended its
duration beyond the space of fourteen or fifteen days were
undoubtedly exaggerated. The nearest approaches to an Indian
Summer which I have witnessed in its proper season have never
lasted a week. In our day, when a warm week occurs in the autumn,
it comes at no regular or expected time. This irregularity of its
occurrence proves that it is not to be identified as the Indian
Summer, which was regular in its happening immediately after the
entire denudation of the forest. Similar but shorter periods of mild
and serene weather may happen, at the present epoch, in winter and
spring as well as in autumn. These irregularities of the weather
cannot be explained; nor can we make predictions of the time when
any of them may happen. But a warm period in October or December
or January is not an Indian Summer, which belonged to November,
and is only a relic of the past.
The origin of the name is explained by Dr. Lyman Foot, in the
third volume of “Silliman’s Journal.” He says: “If you ask an Indian
in the fall when he is going to his hunting-ground, he will tell you
when the fall summer comes, or when the Great Spirit sends our fall
summer; meaning the time in November which we call the Indian
Summer. And the Indians actually believe that the Great Spirit sends
this mild season in November for their special benefit.”
THE POPLAR.

In the latter part of April, some of the most conspicuous groups in


many of the wooded districts of Northern New England are Poplar
woods, full of olivegreen aments, and giving the hue of their
blossoms and of their pale green spray to large portions of the forest
in scattered assemblages. At this period the poplars are an important
ingredient in our wood-scenery, especially as their colors vary
considerably from those of other trees until all kinds are in full
foliage. They have the merit also of preceding a greater part of the
forest in the development of their flowers. The aments of a few
species are variegated with red and purple stamens; but the
generality do not vary from a pure olive. The Poplar has not many of
the qualities of a beautiful or picturesque tree. It is marked by a
coarse and straggling spray, without any variety in its combination.
It is deficient in beauty and density of foliage, which is chiefly
remarkable for its fragrance and tremulous habit.
All the poplars are rapid in their growth, and will prosper in
almost all situations. They prefer a moist, sandy soil, but shun the
peat meadow. Their rapidity of growth renders them valuable where
a speedy plantation is wanted. Hence they are very generally planted
by the sides of dusty thoroughfares, not being dainty in their choice
of soil and situation. The species generally employed for such
purposes is the Abele, or Silver Poplar, which possesses these
requisite properties in a higher degree than our native trees. It
displays also more beauty of foliage, and takes a rounder and
handsomer shape than most others. One of the defects which I have
frequently observed in the shape of the large poplars is a leaning of
the branches rather awkwardly toward the south-east, caused by the
prevalent north-west winds acting upon branches of great
proportional length, and possessing very little elasticity. This
inclination is observed more or less in other soft-wooded deciduous
trees.
THE CANADA POPLAR.
The Canada or Balm of Gilead Poplar is more frequent by our
waysides than any other species. It is a tree of the first magnitude,
attaining a great size in the bole as well as a superior height. It is
distinguished by its large leaves, of a bright glossy verdure, and its
long branches, always subordinate to the central shaft, which may be
traced nearly to the summit of the tree. Before the leaves begin to
expand, the buds are covered with a yellow glutinous balsam, that
diffuses a peculiar and very penetrating but agreeable odor, unlike
any other. Sir John Franklin remarks that this tree constitutes “the
greatest part of the drift timber observed on the shores of the Arctic
Sea.” It has a very wide geographical range, extending from Canada
to the Missouri River, and is in many places called the Ontario
Poplar. It is abundant in the northern woods, but is found in the
southern parts of New England only by the roadsides and in the
enclosures of dwelling-houses. The balsam is gathered in all parts of
the country as a healing anodyne, and for many ailments it is a
favorite remedy in domestic medicine; but no place has yet been
assigned to it in the pharmacopœias. All the poplars produce more or
less of this substance. It is very different from turpentine, more
agreeable when perceived in the air, but pungent and disagreeable to
the taste.
THE BLACK POPLAR.
There are several of the poplars that are not easily distinguished,
and the different and various accounts of them by botanists have
increased this confusion. Part of the difficulty arises from the
diœcious character of the poplar, causing in some instances the male
and female trees to be mistaken for different species. This is
particularly remarkable in the Balm of Gilead poplar. The female tree
is smaller than the male, with larger leaves, and annoys us by the
abundance of cottony down that covers the ground for a considerable
space around it. The male tree is taller and more spreading, and
would hardly be recognized as the same species.
The Black Poplar is often planted by roadsides with the Canada
poplar, and may be distinguished from it by the greater elegance of
its proportions, its smaller foliage, and, when in flower, by its reddish
and purple catkins. It is preferred to other species on account of an
inferior tendency to that suckering habit which is so disagreeable in
the poplar tribe. It seems to me that no persons who should see the
Canada poplar and the Black Poplar growing side by side, would
hesitate in giving preference to the latter, which is in almost every
point a more beautiful tree.
This species is called in Europe the Athenian Poplar. According to
Selby, “the classic appellation of Athenian Poplar led to the
supposition in England that this species is indigenous to Greece, and
that it derived its name from the city of Minerva. Several learned
botanists were misled by this name; but it was finally ascertained
that North America is its native country, and from its abundance in a
particular township called Athens it received the imposing title of
Athenian Poplar.”
THE RIVER POPLAR.
The River Poplar is not rare in the New England forest, but it is
little known as an ornamental tree. Emerson says: “It is much the
tallest and most graceful of those which grow naturally in New
England. Its foliage is equal to that of the Balm of Gilead in size, and
superior to it in depth of color; and the abundance of its aments in
the spring, and the rich colors of its leaf-stalks and young branches,
when growing in somewhat dry situations, make it a beautiful
object.” The aments of this tree are not olive-colored, like those of
the two aspens, but inclining to red, though not so bright as those of
the black and Lombardy poplars. It is very justly called the River
Poplar, being found chiefly in wet places, near brooksides, on the
banks of rivers, and in alluvial valleys which are liable to be
inundated in spring. This tree displays the characteristic peculiarities
of the family in giving out its lateral branches at a sharp angle and
subordinate to the trunk.
SOUNDS FROM TREES.

“The earliest chant,” says Momsen, “in the view of the Romans,
was that which the trees sang to themselves, in the green solitudes of
the forest. The whisperings and pipings of the favorable spirit in the
grove were repeated by the singer, with the accompaniment of the
pipe.” Certain trees belonging to the sacred groves gave oracular
sounds, which were interpreted by musicians, and received by all
men with faith and reverence. From the earliest ages men have
listened to sounds from trees as music and as the voice of some deity,
affording auguries of future events; for, as they reasoned, if a deity
speaks to us, what sounds would be a more appropriate medium of
communication than those of the trees which formed their temples
and their altars? The sanctity attributed to certain groves by the
ancients was probably owing to some peculiar sounds emitted by the
trees, no less than to the grandeur and impressiveness of their
assemblages.
Every tree, when swept by the winds, gives a sound in harmony
with the character of its leaves and spray. The sounds from the lofty
branches of firs and pines remind the listener of the murmuring of
waters, and inspire the most agreeable sensations. How often have I
sat under the shade of a pine wood, and listened to the fancied
roaring of the distant waves of the sea, as the winds passed through
their foliage. When the breeze commences, we hear the first soft
rippling of the waves; as it increases, succeeding waves of fuller swell
flow tremulously upon the strand, and as the wind subsides melt into
silence as they recede from the shore. Other trees produce very
different sounds. The colors of their leaves, and the glittering lights
from their more or less refractive surfaces, do not differ more than
the modifications of sound drawn from them by the passing winds.
Every tree is a delicate musical instrument, that reminds us of the
character of the tree and the season of the year, from the mellow
soothing tones of willow leaves in summer to the sharp rustling of
the dry oak-leaf that tells of the arrival of winter.
The sounds from trees are a very important part of the music of
nature; but their agreeableness comes rather from certain emotions
they awaken than from the melody of their tones. Nature has
accommodated her gifts to our wants and sensibilities, so that her
beneficence is never so apparent as in the pleasures we derive from
the most common objects. If we are afflicted with grief or wearied
with care, we flee to the groves to be soothed by the quiet of their
solitudes, and by the sounds from their boughs which are tuned to
every healthful mood of the mind. Among the thousand strings that
are swept by the winds, there is always a chord in unison with our
feelings; and while each strain comes to the ear with its accordant
vibration, the mind is healed of its disquietude by sounds that seem
like direct messages of peace from the guardian deities of the wood.
We find in the works of Ossian frequent allusions to the sounds
from trees, to heighten the effect of his descriptions. As the “Spirit of
the Mountain,” he addresses the wind that bends the oaks, and gives
out that deep melancholy sound that precedes a storm, “when
Temora’s woods shake with the blast of the inconstant winds.” He
speaks of the “sons of song” as having gone to rest, while his own
voice remains, like the feeble sounds of the forest, when the winds
are laid. When the aged oak of Morven bends over the stream, its
sounds are mournful, like those of a harp when swept by the wind.
According to Ossian, it is the oak that blends its music with the
sounds of lamentation, and sings the dirges of departed heroes. And
the bard declares that he will cease to mourn for them only when the
music of the oak shall no longer be heard in the groves of echoing
Cona.
When a strong wind prevails, the leaves of all trees are put in
motion, and their sounds cannot be distinguished; and during a
storm the roar of winds among their branches is almost deafening.
This is the grand chorus of the elements; but the sounds that affect
us most agreeably are such as come from light movements of the
wind and harmonize with the warbling and chirping of birds. It is the
aspen that gives out those lulling melodies that spring from the
gentle gales of summer. When we are sitting at an open window on a
still evening, or sauntering in a wood, or musing in the shade of a
quiet nook, when the wind is so calm that the hum of the invisible
insect-swarms, hovering in the air, is plainly audible, then is the
trembling motion of the aspen leaves peculiarly significant of the
serenity of the elements. They produce a tranquillizing sound,
associated with rest in the languor of noonday, or with watching in
the still hours of a summer night.
When the quiet of the atmosphere begins to yield to the
movements of a rising tempest, the aspen, by its excessive agitation,
gives prophetic warning of its approach. Often, in a sultry evening,
the first notice I have received of a rising thunder-storm came from
the increased trepidation of an aspen that stood before my window.
So delicate and sensitive is the foliage of this tree that it is excited to
action by atmospheric changes before that of any other tree is
moved. Thus, while the rustling of the aspen leaf, when gentle,
indicates the tranquillity of summer weather, there is likewise an
expression of melancholy in its tones when more severely agitated,
that forebodes a general stirring of the winds as they come up from
the gathering-place of the storm.
I have spoken only of those sounds from trees which are caused by
the action of the winds upon their leaves and branches. But there are
incidental sounds belonging to the woods, which are modified so as
to produce feelings awakened by no other situation. It is in the deep
stillness of the forest, and over spacious and uninhabited plains, that
we feel most sensibly the peculiar effect of bells, whether it be the
solemn peal of a bell from a church tower or the tinkle of a cow-bell
that reminds us of simple rural life. The ordinary toll of bells is much
more impressive than a chime in these solitudes, because the
artificial melody of the chime does not so agreeably harmonize with
natural sounds.
In winter the sounds from trees, except in a pine wood, are greatly
modified by the absence of foliage. It is at this season, therefore, that
we pay the most attention to incidental sounds. When the snow upon
the ground has been hardened by repeated freezing and thawing, I
have often chosen this occasion for winter rambling in the woods.
The loneliness inspired by their seclusion is never so keenly felt as at
this season, when there are but few sounds from birds and insects.
Then does the stroke of the woodman’s axe affect us with the most
cheerful emotions. It reminds us of the presence of other human
beings in the wood, and enlivens the solitude, as the sight of a little
cottage in a wilderness affords the traveller a sensation of the joys of
home.
THE LOMBARDY POPLAR.

There are not many trees that take the shape of a long spire; but
Nature, who presents to our eyes an ever-charming variety of forms
as well as colors, has given us this figure in the arbor-vitæ, the
juniper, and the Lombardy Poplar. This was the species which was
cultivated by the Romans, the classic Poplar of Rome and Athens. To
this tree Ovid alludes when he describes the resinous drops from the
Poplar as the tears of Phæton’s sisters, who were transformed into
poplars. Smith says: “Groves of poplar and willow exhibit this
phenomenon, even in England, in hot calm weather, when drops of
clear water trickle from their leaves like a slight shower of rain.”

The Lombardy Poplar is interesting to thousands in this country,


who were familiar with it in their youth as an ornament of roadsides,
village lanes, and avenues. It was once a favorite shade-tree, and still
retains its privileges in some ancient homesteads. A century ago,
great numbers of Lombardy Poplars were planted by village
waysides, in front of dwelling-houses, on the borders of public
grounds, and particularly in avenues leading to houses that stand at
some distance from the high road. A row of these trees is even now
suggestive of an approach to some old mansion, that still retains its
primitive simplicity.
LOMBARDY POPLAR.

Great numbers of Lombardy Poplars were destroyed at the


beginning of this century, from the notion that they generated a
poisonous worm or caterpillar. But some of these ancient rows of
poplars are occasionally seen in old fields where almost all traces of
the habitation they accompanied are gone. There is a melancholy
pleasure in surveying these humble ruins, whose history would
illustrate many of the domestic habits of our ancestors. The cellar of
the old house is now a part of the pasture land; and its form may be
dimly traced by an angular depression of the surface. Sumachs and
cornel-bushes have supplanted the exotic shrubbery in the old
garden; and the only ancient companions of the Poplar now
remaining are a few straggling lilacs, some tufts of houseleek, and
perhaps, under the shade of a dilapidated fence, the white Star of
Bethlehem is seen meekly glowing in the rude society of the wild
flowers.
But the Lombardy Poplar, once a favorite wayside ornament, a sort
of idol of the public, and, like many another idol, exalted to honors
beyond its merits, fell suddenly into contempt and neglect. After
having been admired by every eye, it was spurned and ridiculed, and
cut down in many places as a cumberer of the ground. The faults
attributed to it were not specific defects of the tree, but were caused
by a climate uncongenial to its nature. It was brought from the sunny
clime of Italy, where it had flourished by the side of the orange and
myrtle, and transplanted to the snowy plains of New England. The
tender habit of the tree made it incapable of enduring our winters;
and every spring witnessed the decay of many of its small branches.
It became prematurely aged, and in its decline carried with it the
marks of its infirmities.
With all these imperfections, it was more worthy of the honors it
received from our predecessors than of its present neglect. It is one
of the fairest of trees in the greenness of its youth, far surpassing any
other poplar in its shape and in the density and general beauty of its
foliage; but nearly all these old trees are gone, and few of the same
species are coming up to supply their places. While I am writing, I
see from my window the graceful spire of one solitary tree, towering
above the surrounding objects of the landscape. It stands there, the
symbol of decayed reputation; in its old age still retaining the
primness of its youth, neither drooping under its infirmities nor
losing in its decrepitude the fine lustre of its foliage. In its disgrace, it
still bears itself proudly, as if conscious that its former honors were
deserved, and not forgetting the dignity that becomes one who has
fallen without dishonor.
There is no other tree that so pleasantly adorns the sides of narrow
lanes and avenues, or so neatly accommodates itself to limited
enclosures. Its foliage is dense and of the liveliest verdure, making
delicate music to the soft touch of every breeze. Its terebinthine
odors scent the vernal gales that enter our open windows with the
morning sun. Its branches, always turning upwards and closely
gathered together, afford a harbor to the singing birds, that make
them a favorite resort; and its long, tapering spire, that points to
heaven, gives an air of cheerfulness and religious tranquillity to
village scenery.
Welcome to our website – the ideal destination for book lovers and
knowledge seekers. With a mission to inspire endlessly, we offer a
vast collection of books, ranging from classic literary works to
specialized publications, self-development books, and children's
literature. Each book is a new journey of discovery, expanding
knowledge and enriching the soul of the reade

Our website is not just a platform for buying books, but a bridge
connecting readers to the timeless values of culture and wisdom. With
an elegant, user-friendly interface and an intelligent search system,
we are committed to providing a quick and convenient shopping
experience. Additionally, our special promotions and home delivery
services ensure that you save time and fully enjoy the joy of reading.

Let us accompany you on the journey of exploring knowledge and


personal growth!

ebookmass.com

You might also like