100% found this document useful (4 votes)
38 views

[Ebooks PDF] download JavaScript: A Beginner's Guide, Fifth Edition Pollock full chapters

Pollock

Uploaded by

adhoraariumo
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
100% found this document useful (4 votes)
38 views

[Ebooks PDF] download JavaScript: A Beginner's Guide, Fifth Edition Pollock full chapters

Pollock

Uploaded by

adhoraariumo
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 50

Get ebook downloads in full at ebookmeta.

com

JavaScript: A Beginner's Guide, Fifth Edition


Pollock

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

OR CLICK BUTTON

DOWNLOAD NOW

Explore and download more ebook at https://ebookmeta.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://ebookmeta.com/product/javascript-a-beginners-guide-fifth-
edition-john-pollock/

ebookmeta.com

JavaScript Absolute Beginner s Guide 2nd Edition Kirupa


Chinnathambi

https://ebookmeta.com/product/javascript-absolute-beginner-s-
guide-2nd-edition-kirupa-chinnathambi/

ebookmeta.com

Learning Web Design A Beginner s Guide to HTML CSS


JavaScript and Web Graphics 5th Edition Jennifer Niederst
Robbins
https://ebookmeta.com/product/learning-web-design-a-beginner-s-guide-
to-html-css-javascript-and-web-graphics-5th-edition-jennifer-niederst-
robbins/
ebookmeta.com

Nature's Radical Honesty: A practical application of


Naturosophy Cory Edmund Endrulat

https://ebookmeta.com/product/natures-radical-honesty-a-practical-
application-of-naturosophy-cory-edmund-endrulat/

ebookmeta.com
Fireworks Every Night: A Novel 1st Edition Beth Raymer

https://ebookmeta.com/product/fireworks-every-night-a-novel-1st-
edition-beth-raymer/

ebookmeta.com

WhatsApp: The essential step-to-step manual to mastering


your WhatsApp and account security 12th Edition Black Dog
Media
https://ebookmeta.com/product/whatsapp-the-essential-step-to-step-
manual-to-mastering-your-whatsapp-and-account-security-12th-edition-
black-dog-media/
ebookmeta.com

Money Matters Find the Money Financial Literacy Linda


Claire

https://ebookmeta.com/product/money-matters-find-the-money-financial-
literacy-linda-claire/

ebookmeta.com

Five Old Men of Yellowstone The Rise of Interpretation in


the First National 1st Edition Stephen Biddulph

https://ebookmeta.com/product/five-old-men-of-yellowstone-the-rise-of-
interpretation-in-the-first-national-1st-edition-stephen-biddulph/

ebookmeta.com

Mechanical Vibration Theory and Application 5th Edition


Haym Benaroya

https://ebookmeta.com/product/mechanical-vibration-theory-and-
application-5th-edition-haym-benaroya/

ebookmeta.com
Her Russian Savior 1st Edition M.K. Moore & Chashiree M.
[Moore

https://ebookmeta.com/product/her-russian-savior-1st-edition-m-k-
moore-chashiree-m-moore/

ebookmeta.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
Other documents randomly have
different content
The Project Gutenberg eBook of Sink or swim?
This ebook is for the use of anyone anywhere in the United States
and most other parts of the world at no cost and with almost no
restrictions whatsoever. You may copy it, give it away or re-use it
under the terms of the Project Gutenberg License included with this
ebook or online at www.gutenberg.org. If you are not located in the
United States, you will have to check the laws of the country where
you are located before using this eBook.

Title: Sink or swim?


a novel; vol. 1/3

Author: Mrs. Houstoun

Release date: December 31, 2023 [eBook #72560]

Language: English

Original publication: London: Tinsley Brothers, 1868

Credits: Sonya Schermann, Chuck Greif and the Online Distributed


Proofreading Team at https://www.pgdp.net (This file was
produced from images generously made available by The
Internet Archive)

*** START OF THE PROJECT GUTENBERG EBOOK SINK OR SWIM?


***
CHAPTER I., II., III., IV., V., VI., VII., VIII., IX., X., XI.,
XII., XIII., XIV., XV., XVI., XVII., XVIII., XIX., XX., XXI.,
XXII.

SINK OR SWIM?
A Novel.

BY THE AUTHOR OF

“RECOMMENDED TO MERCY,”

ETC.

IN THREE VOLUMES.

VOL. I.

LONDON:
TINSLEY BROTHERS, 18 CATHERINE ST. STRAND.
1868.

[The right of translation and reproduction is reserved.]

LONDON:
ROBSON AND SON, GREAT NORTHERN PRINTING WORKS,
PANCRAS ROAD, N.W.
SINK OR SWIM?
CHAPTER I.

WHAT THEY SAID IN THE VILLAGE.


“If I hadn’t heard it from Mrs. Clay herself, I never would have believed it!
To think that John Beacham, who’s a sensible man as men go, should be
marrying an Irishwoman! If Honor Blake was English-born now, one
wouldn’t blame him so much; but to choose a girl that comes of people
who, as everyone knows, you can’t trust farther than you can see them, is
what I call a sin and a shame.”
The speaker was a woman of low stature, elderly, and sharp of voice and
feature. She was seated at a round old-fashioned mahogany table, on which
a teapot of the material known as Britannia metal steamed with a pleasant
warmth, while the odour of buttered toast, “hot and hot,” filled the little
room in which she and a chosen chum and gossip had met together to talk
over the domestic affairs of their friends and neighbours.
The name and title of the first-mentioned lady was Mrs. Thwaytes, and
she, being at the present time a widow, and highly respected, kept a small
general shop in an old-fashioned village, to which I shall give the name of
Switcham. This village, situated near the grandest and most imposing of
England’s rivers, could be reached by express train in something a little
under an hour and a half from London. It was, considering this proximity,
rather a behindhand village. Progress had not hitherto made any gigantic
strides in the old-world-looking place, where not a single house was less
than a century old, and where the aged inhabitants of the quiet spot had not
as yet ceased to speak of crinoline as an abomination, and the absence (on
young women’s heads) of that decent article called a cap as a sign and
symbol of a lost and abandoned soul.
The guest of the widow Thwaytes was qualified in many ways to be that
highly-respected personage’s confidential friend and favourite gossip. A
widow indeed she was, forlorn and desolate by her own account, but
comfortable withal in outward circumstances, and possessed of a portly
person, and a complexion indicative of good cheer and inward content. Mrs.
Tamfrey, for that was the relict’s name, had been left (like the congenial
friend above named) with an only daughter to solace her declining years;
and, after duly casting that young woman upon her own resources as a
domestic servant, she—the widow of the deceased Mr. Tamfrey, a
journeyman carpenter in a comfortable way of business—had entered upon
the attractive career of a monthly nurse. In this lucrative profession she had
met with marked and flattering success. Endowed with a low voice, a
caressing manner, and a universal fund of anecdote, as well as considerable
powers of invention, “Mrs. Tam,” as she was habitually called, made her
way very successfully among the matrons, young and middle-aged, of the
district; and over a cup of a “woman’s best restorer, balmy tea,” the widow
Tamfrey was very generally allowed to be—during the pauses between her
professional engagements—very excellent company.
The room in which these well-suited friends had met for the purpose (not
openly avowed, but nevertheless existent) to which I before alluded was a
snug but not very spacious apartment running parallel with, and having easy
access to, the shop. Miss Thwaytes, the widow’s only daughter, and a young
person verging on forty, was occupied in the said shop—waiting upon
customers and keeping up the credit of the establishment by civil speeches
and oft-repeated remarks on the beauty of the weather and other such banal
topics of conversation. A wonderfully useful person in her way was Esther
Thwaytes; a thorough woman of business, keen-eyed, calculating, and with
only the very smallest of soft spots in the woman’s heart beating under her
maidenly bosom. But there was yet another purpose besides that of business
utility to which Miss Esther Thwaytes was daily put. With her the aged
mother, who possessed but that one ewe lamb, was always indulging in, not
sweet converse, gentle reader—not the interchange of soul with soul, nor
the pleasant fellowship of congenial trencherwomen—but the inexhaustible
enjoyment, the indescribable satisfaction of what we have heard described
in five single letters as “words.” They were both—the daughter of forty and
the parent of sixty-five—essentially “naggers.” The daily food of snip-snap,
the eternal picking of bones, was as necessary to them as the air they
breathed. Deprived of wholesome excitement, the lives of these two women
would have been horribly flat and uninteresting; a vis inertiæ, despite the
busy shop, the cheering tea-drinkings, and the friendly intercourse with that
unfailing gossip Mrs. Tamfrey, the monthly nurse of Switcham.
That exemplary village functionary was pouring out her third dish of tea
when, with a wheezy sigh, she commenced a reply to her friend’s comment
on the approaching marriage.
“As sure as I sits here, Jane Thwaytes,” she said oratorically, “if John
Beacham marries that Irish gurl he’ll come to trouble. There’s that about
Miss Blake as speaks a vollum. It isn’t that she’s, so to speak, aither bold or
forrard; I couldn’t say that of her—no, not if I was to be put upon my Bible
oath; but what I do say is, that she’s got a look with her eyes that I would
have whipped my daughter out of before she was twelve years old, or I
would have known the reason why.”
“It’s singular now, ain’t it,” suggested Mrs. Thwaytes, “that one can’t
learn more about who she is, and where she comes from? A nussery
governess too isn’t much to boast of neither, and I don’t wonder as the old
lady is a bit put out. The Beachams have allers held their heads high, and
John’s mother hasn’t been behindhand with ’em. She’s not the woman, I’m
thinking, to like being mother-in-law to a gurl who may, for anything that’s
known, be a gentleman’s love-child. And, pretty as she is—I must say that
for her—and like a lady too, Miss Blake had to dress the children, and hem
the pincloths, and all that sort of thing at Clay’s Farm.”
“All that sort of thing! I should think so, and a precious deal more to
that. Why from the first moment that Mrs. Clay was took in labour—and
that’s been twice in the two years that Miss Blake’s been at the farm—the
most of the head-work fell upon Honor. There was this to be thought of, and
that to be done—the children to be kep from noise, and the master from
being put out because the baking was spoiled. Everything, morning, noon,
and night—and I used to think it was a bit too much for such a mere girl as
she is—fell upon the nussery governess.”
“And that’s true, I believe, or the Clays, one and all, wouldn’t make so
much of her as they do; and the old lady ought to think of that, proud as she
is, for she’ll be a rare help, will Honor, at the Paddocks. A good headpiece
of her own, and not above making herself useful; and add to that that John’s
getting on for forty, and is particular in his ways—so he is. He means
honourable, does Mr. Beacham, and stands high with rich and poor, and
what’s more, he can take his wife to as good a home as any in the country.”
“Better, maybe, for his wife if it was a poorer one,” said Mrs. Tamfrey,
who knew something of the world and of human nature. “When a young
gurl that’s been used to work marries a man that can keep her without it, ten
to one that she gets into mischief. I don’t say, if she gits a family about her,
which it’s a’most certain she will,” continued Mrs. Tam, speaking, as was
only natural, in the interests of her profession, “that Mrs. John Beacham
won’t settle down; but she’s but a giddy thing at present, always laughing—
I declare it’s the prettiest thing to hear her, and makes one laugh, too, for
company; but if she don’t have a family—and John Beacham’s nearly old
enough to be her father—and if the young men get about her, why”—and
Mrs. Tam, deeming, probably, that she had said enough to enlighten the
feminine mind of her auditor, wound up her prognostications with a very
suggestive sigh.
“I hope not. It would be a sad thing, indeed, if mischief came of this
grand marriage of hers. I should be sorry for John Beacham if it was to,”
mumbled the widow Thwaytes, whose mouth was fuller than was altogether
becoming of well-salted buttered toast. “I should be sorry as sorry could be
for John if trouble was to come upon him that way. Ah well! if the Squire
had only lived! Such a gentleman as he was for advising and keeping things
straight! There isn’t a day nor yet an hour that the parish doesn’t feel the
want of him. If Squire Vavasour had been spared, things would have gone
on, as we’ve all on us said a hundred times, in quite another guess sort of
fashion. There would have been more living at the Castle then, and a
precious sight more money spent in the parish. The Castle then would have
been a proper house for young people to live in, and be married out of; and
now what is it? As Mrs. Shepherd says—and she ought to know that’s been
housekeeper these twenty years at the great house—there’s as much
skinflinting there as if milady hadn’t as many pounds as she has thousands.
‘I declare,’ says she to me, which it will be a week to-morrow, the day I was
taking tea with her up at the Castle,—‘I declare,’ says she, ‘it’s a sin and a
shame how little’s been spent this five years at Gillingham Castle. The
Chace itself and the game and all has been let to go to rack and ruin. Next
to no labourers employed, no parties given where there used to be a’most
open house kep, and such a home made for the young gentlemen as it’s no
wonder they should run a little wild when they was let out like.’”
“There’ll be a change now, I’m thinking,” suggested Mrs. Tamfrey after
a pause; “the young ladies are getting on, you know, and Mr. Arthur coming
of age next year will make something of a stir, in course.”
The widow shook her head with a dreary air of superior wisdom. “From
what Mrs. Shepherd tells me”—and the words were said in one of those
ominous whispers that are intended to imply even more of knowledge than
is expressed—“from what Mrs. Shepherd says, there’s no coming of age yet
awhile for the air aperient of Gillingham. There’s something out of the
common, it appears, though what it is Mrs. Shepherd couldn’t speak to
exactly, in the last entail. Anyway, milady—which seems odd, don’t it? she
having been the heiress—hasn’t got, after a certain day—that’s pos—
anything to do with the estate and property. It’s that, folks say—them as
knows something about the matter—as puts her out so. And it’s to be, some
says, when Mr. Arthur is five-and-twenty that his mamma will have to walk
out of her own house like a private person, after all the money and land that
she was born to.”
“Let milady alone,” put in Mrs. Tam decidedly; “she’ll be rich enough, if
all’s true, whatever happens. There’s a pretty long purse a-filling
somewhere, I’ll be bound. It’s little besides her name that she gives to all
them mad-houses and county ’ospittles that there’s such a talk about. No,
no; Milady Millicent isn’t one to be short of cash, whoever else goes to the
wall—but,” interrupting herself, “my gracious! Jane Thwaytes, if there ain’t
two parties a-waiting in the shop, and no one in life to serve them but
Esther!”
Startled by this appeal to her love of gain and order, the widow, after a
hurried wipe of her lips with the corner of her apron, bustled into the
adjoining shop with a sharp rebuke already on her tongue. It was a tidy and
very prosperous establishment that of which Esther Thwaytes was the prop
and mainstay. In it you could obtain all that the heart of a reasonable
woman of simple tastes and habits ought to desire. On one side, the counter
was strewed with cheap ribbons, snowy cap-fronts, artificial flowers more
gaudy than artistic, with occasionally a tempting novelty in the shape of the
last new thing in bonnets. The other side of the widow’s flourishing “store”
contained goods that were more useful than ornamental. Tea, coffee,
tobacco, and snuff, together with other articles of home and colonial
produce, were procurable at “the” shop in the main street of Switcham. As a
matter of course, the widow, enjoying the benefit of a monopoly, drove a
thriving trade; and, equally as a matter of course, incessant were her
jeremiads on the disjointedness of the times, the dearness of provisions, the
iniquity of subordinates, and the general decadence of all things since the
days which she was pleased to call “her time.” And yet, at scarcely any hour
of the day from the early hour of opening was the little shop devoid of
customers; while towards the witching time of evening, and that more
especially on a Saturday night (for the widow was no advocate for early
closing), her house was one, it may be said, of “call”—a regular rendezvous
for the busy and the idle, for the sweethearts and the gossips, of the village
where the much-respected widow had been born and bred.
CHAPTER II.

THE ANTECEDENTS OF MILADY.


The Lady Millicent Vavasour, whose proceedings were thus so freely
commented upon by her inferiors, was the only child of the rich and potent
Earl of Gillingham. That nobleman, who survived the Countess, his wife,
but little more than a year, bequeathed at his decease, with restrictions and a
good deal à contre cœur, all that he possessed, in land, mines, personalty,
and otherwise, to his only child, the Lady Millicent aforesaid and in the last
chapter duly commented upon.
The income produced by the above-mentioned properties—of all of
which the heiress came into undisputed possession at the age of twenty-
three—amounted at a moderate computation to thirty thousand pounds per
annum. The Lady Millicent Vavasour therefore took her stand on the
platform of public estimation with the prestige of being one of the richest
heiresses in England.
As might naturally be expected, the eyes of the world and eke the
monster’s tongue had from her earliest womanhood a good deal to look and
say on the subject of the Lady Millicent’s future disposition in marriage.
That she would—like the Maiden Queen of mighty memory, or the banker’s
heiress of nineteenth-century renown—be content to enjoy her power alone,
no one appeared for a single moment to imagine. There exist, always have
existed, and probably always will exist, a large proportion of the bolder sex
of whom it is averred, and safely too, that they are not “marrying men;” but
whoever in his or her experience—and I say it without prejudice—has
heard of a “non-marrying woman”? Such a being, if it were discovered to
exist, would be an anomaly, a lusus naturæ, a freak, so to speak, of the
mighty mother who has done all things not only wondrously, but “decently
and in order.”
But if there be a class of females likely to “go in,” as the saying is, for
celibacy, that class is the genus heiress. There are causes too numerous to
mention that may account for this established fact: the watchfulness alike of
friends and foes; a natural as well as a cultivated suspicion that “men are
not (always) what they seem;” the difficulties attendant on an embarras de
choix; and last, but by no means least in importance, the fear of being
reduced to a second-rate power,—may all be cited as good and sufficient
reasons for the delay which so frequently occurs in the “going off” of an
heiress. As regarded the Lady Millicent Vavasour, the rich partie par
excellence of this story, the last-mentioned cause was, far and away beyond
the rest, the one to which might be attributed the important fact that she had
reached the age of twenty-four while still a single woman.
There is much to be said in excuse for the almost proverbial arrogance
and love of power which marks the woman who is born to greatness. She is
so often taught—if not indeed by words, at least by the deference of those
around her, by the inevitable yielding to her will, and by the kotooing of
dependents—that she is, in her way, a Queen, that it would be rather
surprising if any humbler ideas of her own position should find entrance
into her mind. A great deal has been advanced and written on the
importance of public schools as tending to the discovery of that imaginary
line known as a young gentleman’s “level;” but whether this hoped-for
good is ever attained, and if attained whether it be worth the high price
often paid for its possession, must remain an open question; the distressing
truth however cannot, I fear, be disputed, that the “level” of a young lady
possessed of forty thousand pounds per annum is never likely to be found,
save and except in rare cases of matrimonial felicity—in those exceptional
cases, I mean, where there is no struggle for power, where the Salic law as
exemplified in the nineteenth-century wife is virtually set aside, and where
(but this is a sine quâ non) the husband is in every way worthy of this
heroic act of voluntary self-abnegation.
That the Lady Millicent Vavasour was very far from being the model
woman whose price is far above rubies will very speedily be seen. She was
a cold and unattractive child, and she grew up to be in many respects a cold
and unattractive woman; but that she was so must in a great measure be
attributed to the peculiarity of her “bringing up,” and, strange to say, to the
regretable fact that she was not born to be a man. The Earl and Countess of
Gillingham were both what I must be permitted to describe as “family-
mad.” That the Vavasours were the most ancient, the noblest, and most
exalted of all the races of men upon earth, this elderly and highly
respectable couple religiously believed. Previously to her union with the
last male of this ancient family, the Lady Caroline M‘Intyre (the respected
mother of Lord Gillingham’s heiress) had entertained a foolish
prepossession in favour of the old Scottish blood which ran in her own blue
veins; but the engrafting of her northern race in the still nobler stock of the
Vavasours of Gillingham was sufficient to inoculate her with every
prejudice entertained by Richard, eleventh earl of that most princely house.
They were not—barring this one folly—either a particularly silly or an
especially objectionable pair. They were a little grand and distant to those
who might be so daring as to claim equality with themselves, but to their
clearly-marked inferiors and to the actual poor they were kind, generous,
and “pleasant.”
Perhaps the person who suffered the most from the “madness” which
may be said to be inherent in the Vavasour blood was their only child—the
Lady Millicent, whose career will form one of the subjects of these pages.
To her, without intending to be otherwise than affectionate and kind, the
behaviour of both father and mother was invariably cold and distant. She
was never forgiven for the “sin” of her birth—never pardoned, poor
unconscious child, for the guilt of being a girl! As the last male descendant
of the Vavasours, Lord Gillingham would willingly have given ten years at
least of his vast rent-roll, for a son in whose person the grand old title might
be perpetuated; and the Countess his wife fully shared in what she deemed
his very natural discontent. To bear without murmuring this crumpled rose-
leaf on their luxurious couch was not in the nature of either; so instead of
making the best of the only child with which Providence had blessed them,
they did precisely the contrary; and the little Lady Millicent, deprived of the
caresses and the softening influence of a gentle mother’s love, grew up as I
have described her to be—cold, arrogant, and unamiable.
The young lady herself was fully capable of appreciating the wrong that
had been done, not only to her family but to society at large, by the
deplorable accident of her birth. As one of the richest heiresses in England,
and as the bearer of a name so noble and so honoured, she was of course a
“personage;” and as one of the uppermost (that could not be denied) of the
upper ten thousand she would take her place, and an exalted place too,
among the great ones of the land; but—there was the rub!—there “pinched
the shoe,” and “galled the withers”—she was not and would not be, in the
course of nature, a peeress! Power—the power that wealth would give—
was hers, but precedence—that honour so dearly valued by her sex—was
sadly and, unless it were obtained by marriage, for ever wanting.
When, after her parents’ decease, which occurred soon after she had
completed her twenty-third year, the orphaned heiress pondered regretfully
upon these things, the idea of purchasing with her valued thousands one of
the highest of England’s titles could scarcely fail to occur to one whose love
of rank—the well-imbibed prejudice of a dull and unsympathised-with
childhood—was only outdone by her passionate attachment to power. Well
did the Lady Millicent know—for her girlhood had not all been spent in the
seclusion of Gillingham, and at London balls and routs and dinner-parties
she had learned something of the level of gold—well did the heiress know
that, were she willing to barter her rent-roll for rank, the negotiation would
have been only too easily effected. But, all things considered, this young
woman was not so willing. Any superiority enjoyed by a husband, any
benefit conferred upon her through him, would—so singularly was she
constituted—have been as gall and wormwood to her taste. She was
overweeningly proud, besides, even as her parents had been before her, of
the name she bore; and, singular as it may at first seem, it was to that very
pride in, and attachment to the name of Vavasour that the tardy marriage of
this proud and impracticable lady was owing.
Late in the summer of the year following on her accession to wealth and
power, the Lady Millicent set forth in great state on a continental tour. As
companions on the way she had chosen Lord and Lady Merioneth: a good
simple-minded pair, ready and able to be amused, and withal tolerably slow
to comprehend (from the circumstance of their own entire want of foolish
family pride) the besetting sin of their young companion.
The delicate health of Lady Millicent Vavasour was, to the surprise of
the world in general, the alleged motive for her spending the winter abroad.
It had been suddenly discovered that the lungs of the heiress were delicate;
and although her breadth of chest and generally healthy appearance tended
to correct the assertion, public interest—no unusual occurrence when the
malade imaginaire, or otherwise, happens to be a millionaire—was
immediately enlisted in “poor dear” Lady Millicent’s behalf. “So young!”
“so gifted!” “so attractive!” It would, indeed, be hard (and a “liberty” was
implied, if not actually spoken) if Death should venture to approach within
hailing-distance the august person of the Lady of Gillingham. Happily,
however, as it soon became manifest, there was no immediate danger that
the wealth of the heiress would be turned into some obscure and probably
(to the public) uninteresting channel. Long before the money-scattering
English party had reached Florence the Lady Millicent had thrown off every
appearance of invalidness, and was ready for any amusement suitable to her
exalted position which chance might throw in her way. And ready, too, for
something more than amusement—ready to be softened into as much love
as her nature was capable of feeling, by one worthy of the best affections of
a far worthier woman than was the Lady Millicent Vavasour. Cecil
Vavasour was a cousin, many times removed, of that autocratic lady—the
descendant of a junior branch of the noble family whose name he bore; and,
moreover, in his branch of the family there existed the title of baron—a title
which there was every probability would eventually be borne by this poor
and comparatively obscure relation. Comparatively obscure, for in a world
of his own—a world that was not that of the Lady Millicent Vavasour—the
intellectual but retiring Cecil was known and honoured. She for that reason,
among others too insignificant to mention, had never till on the occasion of
this her first continental trip chanced to fall in with her kinsman; and when
at last she did make his acquaintance, the effect of even a first meeting was
marked and decisive. Not that there was much in Cecil Vavasour’s outward
man calculated to touch a woman’s fancy or to win her heart. He was some
years past thirty, and in person neither handsome nor the reverse; but there
was a something undefinably attractive even in the reserve of manner, that
spoke of latent power, and of an intelligence above that of ordinary and
unreflecting mortals. He was tall, too, and of a stately presence; one of
those men, in short, to whom, both physically and mentally, a woman, be
she ever so highly placed in her own estimation, would hardly have refused
to pay the tribute of tacitly acknowledging to her own self that he was her
master. Cecil’s father, a practical though not exactly a discerning man, had
intended his only son for the Bar; but circumstances, to say nothing of the
young man’s own individual tastes, decided against the realisation of the
old gentleman’s plans. A short sojourn in Italy, whither he had gone to
protect and comfort an invalid sister, whose days when she left the shores of
England were already well-nigh numbered, had completed the dislike to his
profession which before had been little more than a surmised distaste.
Cecilia Vavasour died a tranquil death in the soft climate of Tuscany; and
her brother, throwing law study to the winds, and leaving Blackstone to
grow dusty on its shelves, remained to make the best of his three hundred a
year in the sunny land that he had learned so soon to love.
Cecil Vavasour had been three years in Italy—a busy idler, devoted,
almost to idolatry, to the Beautiful that has survived the touch of Time; as
well as to the memories, the associations, and the soft sadness that cling
around the decaying ruins of the past. He had roved from place to place,
mixing little in society, but yet not actually shunning communion with his
fellows, when Lady Millicent arrived at Florence. It would have been
impossible, even had he felt the wish (which he did not) to avoid his cousin,
for the quondam barrister not to become intimate with the heiress of
Gillingham. At first he was very shy—as shy as a proud poor man was
almost certain to be under the peculiar circumstances in which he was
placed. Compared to the cousin, who called him Cecil, and treated him
from the first with marked kindness and consideration, he might well be
termed an impecunious relation. Had Lady Millicent’s conduct towards him
been different—had she behaved to him with anything approaching to her
usual rigid arrogance—his poverty would have troubled Cecil Vavasour but
little. It was his young kinswoman’s gentleness, her unwonted amiability,
her actual deference towards himself, that, while it rendered him ill at ease
in her society, both puzzled and touched him. He little guessed, while
gradually falling under the spell of a woman who in youth was not destitute
of personal attractions, and who could be agreeable when she chose, what
was the true mainspring of her conduct regarding him. He could form no
idea of the hidden demon of Pride lurking beneath that still exterior. To his
thinking, Lady Millicent Vavasour—young, courted, with tens of thousands
yearly at her command, with power to effect so vast an amount of good to
others, and (which we fear was almost equally enviable in Mr. Vavasour’s
sight) with wealth to indulge to the utmost every æsthetic taste—was
scarcely likely to ambition any extra or unpossessed advantage. And then he
was himself so utterly unassuming, so entirely unaware that he in his own
person owned, or was likely ever to own, gifts that the rich heiress of
Gillingham could covet, that, as I said before, he was at the beginning
almost more puzzled than gratified by her notice.
That this state of things should have occasioned at first a something of
distance in the relations between the cousins is not surprising, nor need it
afford subject for wonder that that very distance lent a piquancy to their
intercourse which was not, to the petted heiress at least, without its charm.
Lady Millicent had been so beset by flatterers, and so cloyed by adulation,
that the silence, the fits of absence, and the almost brusqueries of her cousin
Cecil were greeted by her as a very agreeable variety. She was sick to death
of oversweet confections, of butter and honey she had been positively
surfeited, so that the honest brown-bread diet, dry and husky though it was,
which was all that she appeared likely to obtain from Cecil Vavasour, tasted
fresh and wholesome to her fevered palate.
But there was, as I before said, another cause—the cause, in fact—for
Lady Millicent’s obvious appreciation of her cousin, and that motive power
was her cousin’s future rank; for Mr. Vavasour, simple as he stood before
her, quiet, unpretending, noticeable for his carelessness of outward
advantages, his simple manners, and his unfashionable dress, could
nevertheless, failing some very abnormal event, be the means of obtaining
for her in a mitigated degree the fulfilment of her long-cherished desire—
the hope of her heart, the insatiable craving, known only to herself, to wear,
while retaining the noble name of Vavasour, the coronet of a British peeress
on her brow.
The courtship, if courtship it could be called, between Lady Millicent
and the future Baron de Vavasour was somewhat singular and out of rule;
and if any distinct offer of marriage were made between the parties—not a
common occurrence, by the way, in set and deliberate phrase, between
acknowledged lovers—that offer was believed by those best acquainted
with the contracting parties to have emanated from the lady. That Cecil
believed—free from personal vanity though he was—in her attachment to
himself there could be no doubt; nothing, therefore, remained for the man
whose own nature was too noble for him to fear for himself the imputation
of mercenary motives, but to put his pride, and his scruples, if such he had,
into his comparatively empty pockets, and to accept the goods which his
millionaire kinswoman had provided for him.
Perhaps, had the autocratic mistress of Gillingham and its dependencies
been better acquainted with the character of Cecil Vavasour, she might have
hesitated longer ere she selected him as the partner of her life. With all her
ambition, she yet required a husband who would understand her character
and enter into her views; and of this Mr. Vavasour soon showed himself to
be incapable. Misled by the natural faith which we all are apt to place in our
own individual judgment, Lady Millicent had discovered imaginary
qualities in the man whom she had honoured with her choice. Deceived by
the extreme composure of manner and the gentle reserve which were among
her kinsman’s outward characteristics, she had given him credit for an
indolence of disposition which she rather approved of than regretted, and
for an inborn pride of race calculated to assimilate satisfactorily with her
own. They were married, and the Lady Millicent was not long in
discovering to her annoyance—for hers was not a character to take a
disappointment to heart—that she had made a fatal mistake. A better man,
nor one possessed of a more conscientious spirit than that which dwelt in
Cecil Vavasour, never walked the earth. That this was so, no one who
boasted the slightest knowledge of character would long doubt. It might be,
though that fact had yet to be decided, that the lawyer manqué was not
likely to be a distinguished man; but the most casual observer would have
decided at once upon the impossibility of his being otherwise than an
upright and a straightforward one. But for all this, and though Mr. Vavasour
proved to be, in the broad and usual acceptation of the term, an excellent
husband, Lady Millicent was, and withal showed herself to be, bitterly and
hopelessly disappointed. It was terrible to find that, instead of sympathising
in her ambitious desires, Cecil was content to devote himself to the
cultivation of his understanding, the care of his wife’s extensive property,
the amelioration of the condition of the poor, and later, as the—to him—
exceeding blessing of children was granted to his hopes, to the education
and moral training of his sons and daughters. At every time and season, and
to all the occupations and interests of her husband, Lady Millicent took
marked exception. She had expected to find him an amiable nonentity, and
instead, there was ever at her side an earnest and highly intelligent
companion; one too who, although he was no rival power ready to edge her
off the throne she so dearly prized, was nevertheless a man who,
entertaining both stern and exalted notions of the responsibilities of the rich,
was not easily to be diverted from the line of duty—often narrow and
difficult—which he had marked out for himself to follow. Under the
vexatiousness of this tardy discovery, Lady Millicent daily fumed and
fretted—fumed and fretted till her temper, never one of the best, grew
peevish and easy of irritation, and till the chafing of the crumpled rose-leaf
against the sensitive skin of the proud woman’s self-esteem grew to be a
painful, and in process of time a never-to-be-cicatrised sore.
Nor was Cecil Vavasour long behindhand in awaking from the one
delusion that had so effectually changed for him the cherished habits of a
life. The conviction that the love in which he had believed had been but a
passing fancy, and the certainty that he was solely valued by her as a
stepping-stone on which to rise to rank, were not subjects for agreeable
reflection. But though Vavasour was capable of feeling keenly the wrong—
for wrong it was—that had been done him, he was the last man in the world
either to complain of, or to grow silently morbid under, its infliction; only
by his deeds could it be surmised that he was an unwilling sharer in the
good things procurable by the Lady Millicent’s gold; and as, previously to
his marriage, he had steadfastly resisted the making of any settlement by
which he could in his own person benefit, so did he, after becoming
convinced of his wife’s indifference, keep with rigid economy his private
expenses within the scope of his own limited means to defray, while he
abstained as much as lay in his power from indulgence in luxuries which
those means would, unassisted, have been inadequate to procure for him.
Setting aside this glaring instance (which it clearly was) of eccentricity,
Cecil Vavasour, as was universally allowed, acted well up to the obligations
imposed upon the rich and powerful. There was no lordly house throughout
the length and breadth of the land in which the rights of hospitality were
exercised with a more liberal hand than at the various residences owned and
occupied by the Vavasour family. At Gillingham Castle especially, where
the establishment was on an almost princely scale, the grand old house was
twice a year brimming over with guests, and far and wide spread the
reputation for “good entertaining” of the Lady Millicent and her consort.
But for all that this was so, and although Cecil Vavasour was loved and
appreciated by the poor, whose invaluable friend and adviser he ever proved
himself to be, he was not generally popular either with his equals or his
superiors in social position. To anyone accustomed to look inquiringly into
human motives, and to those who have gained knowledge of mankind by
enlarged association with their fellows, the fact that Cecil Vavasour, with all
his excellence, his gentleness and his hospitality, was not generally a
favourite, will excite but little surprise. As a rule, the silent and apparently
self-conceited man rarely meets with favour, for silence is too often taken
for a diagnostic of pride, and pride is of all human qualities the one which
both men and women find the most difficult to pardon. But there was yet
another quality, and it was the one to which his taciturnity was mainly to be
attributed, that interfered greatly with the comfort of Cecil Vavasour’s
existence—he was constitutionally, and therefore incurably, shy. Now the
shyness of a middle-aged gentleman who has lived much in society, and
whose intellect is above the average, is one of those “facts” to believe in
which it is necessary that the individual called upon to exhibit this credulity
should be either a physiologist, or himself the victim of mauvaise honte. It
is probable that Mr. Vavasour met with few or none who were capable
either of understanding or making allowances for his infirmity; and thus it
chanced that, though no man living was more formed by nature to enjoy the
blessings of friendship, he passed through life without meeting (of his own
degree) a single congenial soul into whose breast he could pour out his
sorrows, or ask for sympathy with his joys.
What wonder is it if under these circumstances, and with his large warm
heart dependent solely upon them for tenderness and love, he should have
fairly doated on his children? There were four of them. The eldest, Arthur, a
handsome dark-eyed lad, was destined by the provisions of his
grandfather’s will to enter into possession, at the age of twenty-five, of by
far the greater portion of the Gillingham property, provided that on his—the
said eldest son of Lady Millicent Vavasour—arriving at the above-named
age, his mother should not be in legal phrase a femme couverte. This
singular disposition of property occasioned at the time of the Earl’s decease
no little surprise, but owing probably to the circumstance that there was at
that period no “heir male of Lady Millicent’s body” in existence, only a
very limited amount of discontent was mingled with the universal
astonishment of all who thought themselves qualified to give an opinion on
the subject.
The child next in age to this fortune-favoured individual was also a son;
he was little more than a year his brother’s junior, and inherited more of his
father’s disposition than had been engrafted on his elder brother. The two
boys offered (both in person and character) marked contrasts to each other.
The heir was, as I before said, a handsome fellow, tall, dark-eyed, and well
formed. From his cradle he had been a child of whose outward comeliness
any parent might be proud, and Lady Millicent was proud of him
accordingly—proud, but not fond; it was not in her nature to attach herself
to any living being, save and except the heiress of Gillingham: and the
effects of this monopoly of sentiment very soon became apparent in the
young family growing up around her.
Of Horace, her second son, the Lady Millicent was neither proud nor
fond. He was born delicate, and his infancy being a sickly and a
troublesome one, his lady mother took a disgust to the child who was
associated in her mind with doctors’ visits (this great personage, being very
robust herself, had no patience with illness), occasional visits to a nursery
smelling of drugs, and the irritating wailing of a suffering infant. As little
Horace advanced in years, everyone, with the exception of his mamma,
pronounced him to be, though a plain mite of a child enough, a very
engaging and intelligent specimen of humanity. He was very sweet-
tempered too, and docile, “getting” his baby lessons, as the head nurse
expressed herself, twice as quick as Master Vavasour. But then it must be
remembered that Arthur was an elder son; and when a child is born with a
silver spoon in his mouth, anything above the average amount of brains is,
as all the world will allow, a superfluous possession. Two daughters, Rhoda
and Katherine—of whom more hereafter—completed the family, to the care
and education of which Cecil Vavasour, both from a high sense of duty and
following the dictates of his own heart, greatly devoted himself. Perfectly
alive to the injury done to the children by the absence on their mother’s part
of either the appearance or the reality of maternal tenderness, he did all that
lay in his power to remedy the evil; but with the best intentions, a man
cannot in such a case, to any effectual purpose, play a woman’s part. A
father’s caresses to his child lack ever the softness of a woman’s touch; and
moreover Cecil Vavasour’s nature was not, as we know, a demonstrative
one: his constitutional infirmity of shyness, even when alone with the
children in whose well-being his own happiness was bound up, shackled
and oppressed him, proving a sad hindrance to that perfect confidence
between parent and child which is so valuable an element in education. But
although in some respects Cecil Vavasour might fall short in his exalted
aims, though the young people at the Castle might and probably did miss
the invaluable advantage of which they were deprived by Lady Millicent’s
natural hardness of character, they were nevertheless, in one respect at least,
highly favoured. On their father’s unchangeable justice they could ever and
always implicitly rely, as well as on that entire absence of caprice which is
one of the most precious negative gifts with which those in power, whether
great or limited, can be endowed.
Perhaps the main error in Mr. Vavasour’s system of education—for he
had in his deep and absorbing conscientiousness formed a plan for the
bringing-up of his children, from which he never deviated—was, that they
were over-educated, and kept too strictly within the narrow bounds of
standard and routine. He may have forgotten, and it is probable that his lady
wife had never known, that the natural fermentation of human passions
within the breast, if too closely confined therein, is liable to become a
dangerous element. Tie the vessel in which inflammable matter is kept too
tightly and too early down, and when the hot season of the year arrives, and
the working goes on with furious heat within, then bursts the ligature and
out flies the cork, while careful parents, terrified at the explosion, marvel
how, after all their precautions, and the mighty pains they took, there should
be a crash so fearful, and so melancholy a waste of good materials.
There are some men, and of these was Cecil Vavasour, into whose inner
life other, and apparently unauthorised, people entertain a morbid desire to
pry. The question of who really ruled at the Castle was often mooted, not
only in the village of Switcham itself, but throughout the whole of the
adjacent country. That Mr. Vavasour was a very “superior” man, the world
had been from the first quite ready to acknowledge. If any confirmation of
this received fact were wanting, it was to be found, so said the initiated, in
the great and manifest improvement in Lady Millicent’s property since the
epoch of her marriage. This improvement had been brought about so
quietly, and Mr. Vavasour took so little apparent part in the management of
the estates, that it was hard to say at whose instigation, or by whose
superior judgment, so many salutary reforms had been carried out. There
had been no sudden or startling changes. There had not even been an unjust
steward dismissed, or a series of hitherto unsuspected frauds unearthed and
punished. How and when this silent, unboastful man worked so effectually
for the good, not only of his rich wife’s estates, but for the welfare of each
individual amongst the many whom he religiously believed were, in a
manner, intrusted to his charge, was a mystery to all. Nor was this the only
mystery talked over amongst the inquisitive—and they were many—
regarding Cecil Vavasour and his belongings. Was he, asked the curious, a
happy and a contented man? Had the acquisition of wealth opened to him
new sources of enjoyment? Had Lady Millicent’s husband, during the years
of his married life, suffered in mind from domestic disappointment, from
the coldness of his wife’s unsympathising nature, or from her besetting sin
—a mean jealousy of power? It is very probable that he did so suffer, for
those men frequently undergo the most whose exterior is undemonstrative,
and who are to all appearance insensible to the touch of Sorrow’s wand; but
whether Cecil Vavasour were or were not, in these respects, a fitting object
for sympathy, the public never was quite able to make up its mind; for
before such a desirable end could be attained, death, to the regret of all who
knew him, cut short the earthly career of one who might truly have been
called the “poor man’s friend.”
Arthur Vavasour had just completed his fifteenth year—he being then in
the fifth form at Eton—when he received the direful intelligence of a loss
which, to him, was truly an irreparable one. The casualty which rendered
him an orphan had from the first been pronounced by the medical men to be
a serious case. It was occasioned by the accidental going-off of a gun in the
hand of a careless under-keeper, one bright May morning, when Mr.
Vavasour and his younger son, who was the private pupil of a neighbouring
clergyman, were rook-shooting in a distant part of Gillingham Chace. For
several days Cecil Vavasour continued to suffer much and patiently; then on
a sudden all pain left him, and he knew that his doom was sealed. The
report of Mr. Vavasour’s danger spread rapidly through the country, and
people flocked in crowds to the lodge-gates of Gillingham to learn the truth,
and to inquire, with hushed voices and with saddened looks, whether there
were any hope that the good man whose days were numbered might yet be
spared to them. For, if they had never known the value of Cecil Vavasour
before, they recognised it now. When he was about to be removed from
amongst them, there was scarcely one amongst the poor, the sorrowful, and
the troubled but remembered some act of generosity, some sympathising
word, some excellent advice bestowed in time of need. It seemed difficult to
realise the truth that such a man—one too in the full vigour of his life and
strength—was so early destined to go the way of all flesh. To be sure he
was but enduring the lot appointed for everyone that is born of a woman,
and why men should show longer faces, and talk with more whispering
voices of the accidents and losses of the great and wealthy than they are
given to do of the self-same misfortunes when they befall those who are
formed of more common clay, it may at first sight be difficult to understand;
but the fact that so it is remains the same. And thus it chanced that the Lady
Millicent, self-absorbed and phlegmatic though she was, elicited in her
threatened widowhood far more of general sympathy and interest than
would have been awarded to a hundred bereaved and penniless women
sobbing out their hearts’ grief in an atmosphere of poverty and dirt, and
surrounded by ragged orphans howling for the bread-winner who would
return to them no more for ever.
It was well for Cecil Vavasour that he had not left to “the last” the duty
of preparing for the end; for the time allowed him for such preparation was
short indeed. On his bed of death he found courage to speak very frankly to
the wife who stood shocked, miserably disappointed, and perhaps at that
supreme moment remorseful, by his side. In few but solemn words he
committed his children to her care. They would, under God, who is the
Father of the fatherless, be hers only now, hers to guide, to counsel, and to
instruct. On her and on her only would rest, so the dying man in his feverish
anxiety declared to her, their well-being both in this transitory life and in
that to which he was hastening; and as she should do her duty by his
treasures, so, prayed the feeble voice with touching fervour, might He who
judgeth all men have mercy upon her in the world that is to come! They
were his last words. After a faintly-whispered farewell to the old servants,
who were weeping near the door, there remained but the silent pressure of
the death-cold hand, a quiver of the pale lips, as one by one his children
bent their young fresh faces to receive the parting kiss, and the spirit of
Cecil Vavasour entered into its rest.
There was a grand funeral, at which Lady Millicent, in the longest and
crapiest of robes, and utterly devoid of crinoline, assisted, leading her
eldest son by the hand, and looking the bereaved and grieving widow to
perfection. There were many true mourners in the crowd that followed Cecil
Vavasour to the grave, and not a few of these were of opinion that true
sorrow shuns a multitude, and that the newly-made widow who can follow
her husband’s ashes to their last resting-place has not very dearly loved him
in his lifetime. Be this as it may—and it is after all as hard to judge the
feelings of others as it is to estimate their powers of self-control—the Lady
Millicent, surrounded by her children, did conduct herself at her dead
husband’s funeral with a very praiseworthy amount of dignified self-
command. Among those who had been Cecil Vavasour’s friends and
acquaintances there were grave faces and regretful hearts; but the poor wept
for him; and the time soon came, after he had departed from among them,
when folk of all degrees began to see clearly what manner of man he had
been of whom during his unobtrusive life they had known so little.
CHAPTER III.

EVERY DOG HAS ITS DAY.


The approaching marriage of Mr. John Beacham, whose family had been
time out of mind one of the most respected and respectable in the entire
parish of Switcham, within the boundaries of which the Beachams had held
land to a large extent under many a successive lord of the manor of
Gillingham, was a very important event in that quiet locality. In his way,
John Beacham might almost be styled a public character. Far and near,
whenever a certain highly interesting subject—namely, that of horses—was
upon the tapis, honest John’s name was pretty certain to be brought
prominently forward. It was surprising—in a country and on a matter in
which almost every young gentleman, probably, held a first-rate opinion of
his own merits as a judge of “cattle”—what weight the fiat of John
Beacham, farmer and horse-breeder, was wont to carry with it. The latter
vocation—and a highly lucrative one it was—had not been exercised for
more than a dozen years or so by the lessees of Shotover Farm, by which
name, by the way, the hundreds of broad acres rented by the Beacham
family had, for generations past, been known. Some six years before the
death of John’s father, the estate called Updown Paddocks, and which
consisted of many a broad and fertile meadow, admirably adapted for
breeding purposes, was announced to be for sale. It lay in tempting
proximity to Mr. Beacham’s farm; the price in that prudent individual’s
opinion was a reasonable one; he and his trusted son John were agreed in
the matter; so, in due course of time, the tenants of Shotover progressed to
the dignity of landowners. Meanwhile, and pending the final arrangements
for the purchase, John’s mother, the “old lady” of whom honourable
mention has already been made, showed herself anything but favourable to
the new plan. Though a Yorkshire woman born and bred, the love of horses
and of horse-dealing was not inherent in her septuagenarian breast. She was
a tall, large-boned, but, in spite of her seventy years, still a well-favoured
woman. John was her only surviving child, infantile complaints of various
kinds having carried away four others before they had had time to wind
themselves too closely round her heart; and in the said John, therefore—in
his present comfort and his future fortunes—all her best affections and her
keenest interests were concentrated. Many were the anxious moments
endured, and not a few the querulous remarks uttered, by the farmer’s
cautious wife before the complete success of the undertaking, so
judiciously, and withal so conscientiously, carried on by her husband and
son, laid her fears to rest, and effectually put a stop to her gloomy
forebodings of loss and ruin. It is true that the excellent woman was kept a
little in the dark regarding the details of the business which was already
making for the breeding establishment of Beacham and Son a name
throughout the land. The “old lady”—for by that title John’s stately mother
was known in the neighbourhood of her abode—would have been not a
little startled had she chanced to learn the amount of money that had been
invested at Updown Paddocks. She seldom, after having become perfectly
convinced that the “concern” was a safe investment, alluded to the subject;
but it is more than probable that had Mrs. Beacham been required to make a
rough guess at the sum-total expended yearly on the “horse-breeding
business,” she would, without much hesitation, have named something
under half the amount that John, who was no niggard of his cash, thought
nothing of paying for the least costly of his pure-blooded “sires.”
Mrs. Beacham was justly proud of the increase of wealth and
consideration which had accrued to her family by means—as she was fully
justified in believing—of the intelligence and undeviating rectitude of her
husband and son. But, most of all, in the simplicity of her feudal zeal, she
was boastful of the friendship and unfailing regard evinced for both by the
“good Squire,” as he was everywhere denominated (for they were tenants,
not of Mr. Vavasour, but of “milady”), by that discriminating and kindly
gentleman. A deeply-rooted love of the animal of whose race so many noble
specimens were always to be seen at Updown Paddocks would have been
alone sufficient to account for Cecil Vavasour’s frequent visits to Mr.
Beacham’s establishment; but, in addition to this, there was a genuine liking
and sincere respect for the two men who never permitted the desire for gain
to triumph over their sense of honour, and who, although they breathed the
air which is supposed to be so deleterious to honesty, yet retained a pure
and healthy sense of what was due, not only to their customers and
themselves, but to the noble animals on whose merits they so successfully
traded. Cecil Vavasour thoroughly enjoyed the five miles of pleasant
country walk, which had for its end and object a chat with Lady Millicent’s
model tenants—the Beachams of Updown Paddocks. He delighted in their
shrewd uncommon sense, in their practical equine knowledge, in their
cordial welcome, and, above all, in the sight of the young stock gambolling
over the sweet short pasture of the Paddocks, whilst their sober mothers
cropped the staff of their lives in placid and unmolested enjoyment.
The deaths, under very different circumstances, of the Squire and John’s
greatly-regretted father took place within three months of each other. The
illness of the latter was a lingering one, induced by imprudent self-exposure
to wet and cold; and when at last the news went forth that the old man was
no more, deep and general was the regret expressed by all ranks for his loss.
His widow, too, mourned very sincerely for one who had been a good
husband for the space of near upon forty years to her; but then she was so
fortunate as to have “John” to comfort her, and he, as all the neighbours
round would have been ready to acknowledge, was “a host in himself.”

It was the last day of April, the eve of “the maddest, merriest day in all
the glad new year,” and the eve, besides, of John Beacham’s wedding-day
—the day that was to make him, according to his own belief, the happiest of
human beings. The weather was lovely. The spring had been a forward one,
so that there were not wanting lilacs and laburnums, Gueldres roses and
hawthorn blossom, to deck the maypoles and adorn the floral arch which it
was the gallant purpose of the Switcham youths to erect over the
churchyard gate, through which the bridal party had to pass.
The exceeding beauty of the girl who had won what was universally
considered by her peers a prize in the matrimonial market, and a certain
mystery which hung about her origin, would alone have been sufficient,
without reckoning John Beacham’s well-deserved popularity, to account for
the interest and curiosity created by the approaching nuptials. Honor Blake
certainly was very lovely; that could not be denied. Fresh and sweet as a
rose in June, with a profusion of light-brown wavy hair, melting blue eyes
(had they in very truth a “look,” as Mrs. Tamfrey averred, in their languid
depths?), and cherry lips that seemed pouting to be kissed; but for all this
beauty, and partly, perhaps, because of her rich personal endowments,
women—ay, and men likewise—were very curious to learn something
certain and tangible regarding the quondam nursery governess at Clay’s
Farm. All that was positively known regarding John’s fiancée amounted to
this—namely, that her early childhood had been passed at a superior
description of farm-house in the far west of Ireland, and, moreover, it was
very apparent that she had been delicately as well as tenderly reared. At the
age of seven, a person calling herself the child’s aunt had removed the little
Honor from the affectionate care of the “widow Moriarty,” the “snug
woman” who had hitherto acted a mother’s part by the blue-eyed Irish
maiden; and the next important event in the little girl’s life was the being
placed in a respectable country boarding-school, where she completed an
education that was more solid than ornamental. Eventually, and when she
had reached the age of sixteen, Miss Blake, through the medium of the
above-spoken-of relation, whose name was Bainbridge, and who had been
for many years in the service, as housekeeper, of a wealthy Sandyshire
family, obtained the situation of nursery governess at Clay’s Farm. The
Clays were excellent people in their line, and they neither overworked nor
underfed the young person, who did her best, though she was still, as good-
natured Mrs. Clay often said, “but a giddy thing,” to please them.
John Beacham, although he had not been behindhand in admiring
Honor’s beauty, was too busy, and owned too little of a sentimental nature,
to fall in love with her at first sight. She was such a mere child, too,
compared to himself. He, a man of thirty-five, weather-beaten, and with
lines upon his brow, to say nothing of a rare gray hair or two that his old
mother viewed with pain cropping out in his thick brown whiskers, was
many a year too old to mate himself with that bright bud of beauty. But
though steady John Beacham was wise enough in his calmer moments, and
when safe from the glamour of Honor Blake’s blue eyes, to remember these
salutary facts, it was altogether a different affair when he chanced to meet
her, looking so brightly pretty, walking with the farmer’s children in the
shady lanes, or when the little lake, on the borders of Clay’s Farm, was ice-
bound in the cold December weather, making a sunny spot where her sweet
radiant face was seen amongst the busy skaters. There is no need to dwell
upon the not very remarkable particulars of this rustic courtship. John was
Honor’s first lover—the first that she had ever thought or read of. Marriage
—an affair to which she, like every girl of sense, of course looked forward
to—seemed a pleasant, an exciting, and an important event in life. It would
be delightful to have new clothes, and a home and children of her own; for
Honor was very fond of, as well as patient with, little people; and perhaps
her satisfaction at her approaching marriage was more closely connected
with thoughts of baby-smiles and “waxen touches” than the girl herself, in

You might also like