100% found this document useful (2 votes)
14 views

JavaScript: A Beginner's Guide, Fifth Edition Pollock instant download

The document is a promotional material for 'JavaScript: A Beginner's Guide, Fifth Edition' by John Pollock, providing links to download the book and other related resources. It includes information about the author, technical editor, and copyright details. Additionally, it outlines the contents and structure of the book, aimed at beginners learning JavaScript.

Uploaded by

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

JavaScript: A Beginner's Guide, Fifth Edition Pollock instant download

The document is a promotional material for 'JavaScript: A Beginner's Guide, Fifth Edition' by John Pollock, providing links to download the book and other related resources. It includes information about the author, technical editor, and copyright details. Additionally, it outlines the contents and structure of the book, aimed at beginners learning JavaScript.

Uploaded by

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

JavaScript: A Beginner's Guide, Fifth Edition

Pollock download

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

Download more ebook from https://ebookmeta.com


We believe these products will be a great fit for you. Click
the link to download now, or visit ebookmeta.com
to discover even more!

JavaScript A Beginner's Guide Fifth Edition John


Pollock

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

JavaScript Absolute Beginner s Guide 2nd Edition Kirupa


Chinnathambi

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

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/

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/
Fireworks Every Night: A Novel 1st Edition Beth Raymer

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

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/

Money Matters Find the Money Financial Literacy Linda


Claire

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

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/

Mechanical Vibration Theory and Application 5th Edition


Haym Benaroya

https://ebookmeta.com/product/mechanical-vibration-theory-and-
application-5th-edition-haym-benaroya/
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/
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
death; but it turns out, on systematic inquiry, that old age and death
are not essential to living organisms. They represent the
deterioration and wearing out of working parts, so that the vivifying
principle is hampered in its manifestation and cannot achieve results
which with a younger and healthier machine were possible; but the
parts which wear out are not the essential bearers of the vivifying
principle; they are accreted or supplementary portions appropriate to
developed individual earth life, and it does not appear improbable
that the progress of discovery may at least postpone the
deterioration that we call old age, for a much longer time than at
present. Emphasis on this distinction between germ cell and body
cell, usually associated with Weismann, seems to have been
formulated before him by Herdman of Liverpool.
Biologists teach us that the phenomenon of old age is not evident in
the case of the unicellular organisms which reproduce by fission. The
cell can be killed, but it need neither grow old nor die. Death
appears to be a prerogative of the higher organisms. But even
among these Professor Weismann adopts and defends the view that
"death is not a primary necessity, but that it has been secondarily
acquired by adaptation." The cell is not inherently limited in its
number of cell-generations. The low unicellular organism is
potentially immortal; the higher multicellular form, with well-
differentiated organs, contains the germ of death within its soma.
Death seems to supervene by reason of its utility to the species:
continued life of an individual after a certain stage being
comparatively useless. From the point of view of the race the soma
or main body is "a secondary appendage of the real bearer of life—
the reproductive cells." The somatic cells probably lost their immortal
qualities on this immortality becoming useless to the species. Their
mortality may have been a mere consequence of their
differentiation. "Natural death was not introduced from absolute
intrinsic necessity, inherent in the nature of living matter," says
Weismann, "but on grounds of utility; that is from necessities which
sprang up, not from the general conditions of life, but from those
special conditions which dominate the life of multicellular
organisms."
It is not the germ cell itself, but the bodily accretion or appendage,
which is abandoned by life, and which accordingly dies and decays.

Footnotes
[32] See Explanatory Note A at end of chapter.
[33] See Explanatory Note B.
CHAPTER II
THE MEANING OF THE TERM DEATH

"And Life, still wreathing flowers for Death to wear."—Rossetti

W HATEVER Life may really be, it is to us an abstraction: for the


word is a generalised term to signify that which is common to
all animals and plants, and which is not directly operative in the
inorganic world. To understand life we must study living things, to
see what is common to them all. An organism is alive when it
moulds matter to a characteristic form, and utilises energy for its
own purposes—the purposes especially of growth and reproduction.
A living organism, so far as it is alive, preserves its complicated
structure from deterioration and decay.[34]
Death is the cessation of that controlling influence over matter and
energy, so that thereafter the uncontrolled activity of physical and
chemical forces supervene. Death is not the absence of life merely,
the term signifies its departure or separation, the severance of the
abstract principle from the concrete residue. The term only truly
applies to that which has been living.
Death therefore may be called a dissociation, a dissolution, a
separation of a controlling entity from a physicochemical organism; it
may be spoken of in general and vague terms as a separation of soul
and body, if the term 'soul' is reduced to its lowest denomination.
Death is not extinction. Neither the soul nor the body is extinguished
or put out of existence. The body weighs just as much as before, the
only properties it loses at the moment of death are potential
properties. So also all we can assert concerning the vital principle is
that it no longer animates that material organism: we cannot safely
make further assertion regarding it, or maintain its activity or its
inactivity without further information.
When we say that a body is dead we may be speaking accurately.
When we say that a person is dead, we are using an ambiguous
term; we may be referring to his discarded body, in which case we
may be speaking truly and with precision. We may be referring to his
personality, his character, to what is really himself; in which case
though we must admit that we are speaking popularly, the term is
not quite simply applicable. He has gone, he has passed on, he has
"passed through the body and gone," as Browning says in Abt
Vogler, but he is—I venture to say—certainly not dead in the same
sense as the body is dead. It is his absence which allows the body to
decay, he himself need be subject to no decay nor any destructive
influence. Rather he is emancipated; he is freed from the burden of
the flesh, though with it he has also lost those material and
terrestrial potentialities which the bodily mechanism conferred upon
him; and if he can exert himself on the earth any more, it can only
be with some difficulty and as it were by permission and co-
operation of those still here. It appears as if sometimes and
occasionally he can still stimulate into activity suitable energetic
mechanism, but his accustomed machinery for manifestation has
been lost: or rather it is still there for a time, but it is out of action, it
is dead.
Nevertheless inasmuch as those who have lost their material body
have passed through the process of dissolution or dissociative
severance which we call death, it is often customary to speak of
them as dead. They are no longer living, if by living we mean
associated with a material body of the old kind; and in that sense we
need not hesitate to speak of them collectively as 'the dead.'
We need not be afraid of the word, nor need we resent its use or
hesitate to employ it, when once we and our hearers understand the
sense in which it may rightly be employed. If ideas associated with
the term had always been sensible and wholesome, people need
have had no compunction at all about using it. But by the populace,
and by Ecclesiastics also, the term has been so misused, and the
ideas of people have been so confused by insistent concentration on
merely physical facts, and by the necessary but over-emphasised
attention to the body left behind, that it was natural for a time to
employ other words, until the latent ambiguity had ceased to be
troublesome. And occasionally, even now, it is well to be emphatic in
this direction, in order to indicate our disagreement with the policy
of harping on worms and graves and epitaphs, or on the
accompanying idea of a General Resurrection, with reanimation of
buried bodies. Hence in strenuous contradiction to all this
superstition comes the use of such phrases as 'transition' or
'passing,' and the occasional not strictly justifiable assertion that
"there is no death."
For as a matter of familiar fact death there certainly is; and to deny
a fact is no assistance. No one really means to deny a fact; those
who make the statement only want to divert thoughts from a side
already too much emphasised, and to concentrate attention on
another side. What they mean is, there is no extinction. They
definitely mean to maintain that the process called death is a mere
severence of soul and body, and that the soul is freed rather than
injured thereby. The body alone dies and decays; but there is no
extinction even for it—only a change. For the other part there can
hardly be even a change—except a change of surroundings. It is
unlikely that character and personality are liable to sudden
revolutions or mutations. Potentially they may be different, because
of different opportunities, but actually at the moment they are the
same. Likening existence to a curve, the curvature has changed, but
there is no other discontinuity.
Death is not a word to fear, any more than birth is. We change our
state at birth, and come into the world of air and sense and myriad
existence; we change our state at death and enter a region of—
what? Of Ether, I think, and still more myriad existence; a region in
which communion is more akin to what we here call telepathy, and
where intercourse is not conducted by the accustomed indirect
physical processes; but a region in which beauty and knowledge are
as vivid as they are here: a region in which progress is possible, and
in which "admiration, hope, and love" are even more real and
dominant. It is in this sense that we can truly say, "The dead are not
dead, but alive." ούδέ τεθνᾷσι θανὸντες.

APPENDIX ON FEELINGS WHEN DEATH IS


IMMINENT

Preliminary Statement by O. J. L.
A lady was brought by a friend to call on us at Mariemont during a
brief visit to Edgbaston, and I happened to have a talk with her in
the garden. I found that she had been one of the victims of the
Lusitania, and as she seemed very cheerful and placid about it, I
questioned her as to her feelings on the occasion. I found her a
charming person, and she entered into the matter with surprising
fulness, considering that she was a complete stranger. Her chief
anxiety seems to have been for her husband, whom she had left
either in America or the West Indies, and for her friends generally;
but on her own behalf she seems to have felt extremely little anxiety
or discomfort of any kind. She told me she had given up hope of
being saved, and was only worried about friends mourning on her
behalf and thinking that she must have suffered a good deal,
whereas, in point of fact, she was not really suffering at all. She was
young and healthy, and apparently felt no evil results from the three
hours' immersion. She was sucked down by the ship, and when she
came to the surface again, her first feeling was one of blank surprise
at the disappearance of what had brought her across the Atlantic.
The ship was "not there."
I thought her account so interesting, that after a few months I got
her address from the friend with whom she had been staying, and
wrote asking if she would write it down for me. In due course she
did so, writing from abroad, and permits me to make use of the
statement, provided I suppress her name; which accordingly I do,
quoting the document otherwise in full.
The Document referred to

"Your letter came to me as a great pleasure and surprise. I have


always remembered the sympathy with which you listened to
me, that morning at Edgbaston, and sometimes wondered at
the amount I said, as it is not easy to give expression to feelings
and speculations which are only roused at critical moments in
one's life.
"What you ask me to do is not easy, as I am only one of those
who are puzzling and groping in the dark—while you have found
so much light for yourself and have imparted it to others.
"I would like, however, most sincerely to try to recall my
sensations with regard to that experience, if they would be of
any value to you.
"It would be absurd to say now, that from the beginning of the
voyage I knew what would happen; it was not a very actual
knowledge, but I was conscious of a distinct forewarning, and
the very calmness and peace of the voyage seemed, in a way, a
state of waiting for some great event. Therefore when the ship
was rent by the explosion (it was as sudden as the firing of a
pistol) I felt no particular shock, because of that curious inner
expectancy. The only acute feeling I remember at the moment
was one of anger that such a crime could have been committed;
the fighting instinct predominated in the face of an unseen but
near enemy. I sometimes think it was partly that same instinct—
the desire to die game—that accounted for the rather grim
calmness of some of the passengers. After all—it was no
ordinary shipwreck, but a Chance of War. I put down my book
and went round to the other side of the ship where a great
many passengers were gathering round the boats; it was
difficult to stand, as the Lusitania was listing heavily. There
seemed to be no panic whatever; I went into my cabin, a
steward very kindly helped me with a life-jacket, and advised
me to throw away my fur coat. I felt no hurry or anxiety, and
returned on deck, where I stood with some difficulty—
discussing our chances with an elderly man I just knew by sight.
"It was then I think we realised what a strong instinct there was
in some of us—not to struggle madly for life—but to wait for
something to come to us, whether it be life or death; and not to
lose our personality and become like one of the struggling
shouting creatures who were by then swarming up from the
lower decks and made one's heart ache. I never felt for a
moment that my time to cross over had come—not until I found
myself in the water—floating farther and farther away from the
scene of wreckage and misery—in a sea as calm and vast as the
sky overhead. Behind me, the cries of those who were sinking
grew fainter, the splash of oars and the calls of those who were
doing rescue work in the lifeboats; there seemed to be no
possibility of rescue for me; so I reasoned with myself and said,
'The time has come—you must believe it—the time to cross
over'—but inwardly and persistently something continued to say,
'No—not now.'
"The gulls were flying overhead and I remember noticing the
beauty of the blue shadows which the sea throws up to their
white feathers: they were very happy and alive and made me
feel rather lonely; my thoughts went to my people—looking
forward to seeing me, and at that moment having tea in the
garden at —— the idea of their grief was unbearable—I had to
cry a little. Names of books went through my brain;—one
specially, called 'Where no Fear is,' seemed to express my
feeling at the time! Loneliness, yes, and sorrow on account of
the grief of others—but no Fear. It seemed very normal,—very
right,—a natural development of some kind about to take place.
How can it be otherwise, when it is natural? I rather wished I
knew some one on the other side, and wondered if there are
friendly strangers there who come to the rescue. I was very
near the border-line when a wandering lifeboat quietly came up
behind me and two men bent down and lifted me in. It was
extraordinary how quickly life came rushing back;—every one in
the boat seemed very self-possessed—although there was one
man dead and another losing his reason. One woman expressed
a hope for a 'cup of tea' shortly—a hope which was soon to be
realised for all of us in a Mine Sweeper from Queenstown. I
have forgotten her name—but shall always remember the
kindness of her crew—specially the Chief Officer, who saved me
much danger by giving me dry clothes and hot towels.
"All this can be of very little interest to you—I have no skill in
putting things on paper;—but, you know. I am glad to have
been near the border; to have had the feeling of how very near
it is always—only there are so many little things always going on
to absorb one here.
"Others on that day were passing through a Gate which was not
open for me—but I do not expect they were afraid when the
time came—they too probably felt that whatever they were to
find would be beautiful—only a fulfilment of some kind.... I have
reason to think that the passing from here is very painless—at
least when there is no illness. We seemed to be passing through
a stage on the road of Life."

Footnotes
[34] See Note C at end of preceding chapter.
CHAPTER III
DEATH AND DECAY

"All, that doth live, lives always!"—Edwin Arnold

C ONSIDER now the happenings to the discarnate body. In the first


place, I repeat, it is undesirable to concentrate attention on a
grave. The discarnate body must be duly attended to when done
with; the safety of the living is a paramount consideration; the living
must retain control over what is dead. Uncontrolled natural forces
are often dangerous: the only thing harmful about a flood or a fire is
the absence of control. Either the operations must be supervised and
intelligently directed, or they must be subjected to such disabilities
that they can do no harm. But to associate continued personality
with a dead body, such as is suggested by phrases like "lay him in
the earth", or "here lies such an one," or to anticipate any kind of
physical resuscitation, is unscientific and painful. Unfortunately the
orthodox religious world at some epochs has attached superstitious
importance, not to the decent disposal, but to the imagined future of
the body. Painful and troublesome to humanity those rites have
been. The tombs of Egypt are witness to the harassing need felt by
the living to provide their loved ones with symbols or tokens of all
that they might require in a future state of existence,—as if material
things were needed by them any more, or as if we could provide
them if they were.[35] The simple truth is always so much saner and
happier than the imaginings of men; or, as Dr. Schuster said in his
Presidential address to the British Association at Manchester, 1915,
—"The real world is far more beautiful than any of our dreams."
What is the simple truth? It can be regarded from two points of
view, the prosaic and the poetic.
Prosaically we can say that the process of decay, if regarded
scientifically, is not in itself necessarily repugnant. It may be as
interesting as fermentation or any other chemical or biological
process. Putrefaction, like poison, is hostile to higher living
organisms, and hence a self-protecting feeling of disgust has arisen
round it, in the course of evolution. An emotional feeling arises in
the mind of anyone who has to combat any process or operation of
nature,—like the violent emotions excited in an extreme teetotaller
by the word 'drink': a result of the evil its profanation has done; for
the verb itself is surely quite harmless. Presumably a criminal
associates disagreeable anticipations with the simple word 'hanging.'
The idea of a rank weed is repulsive to a gardener, but not to a
botanist; the idea of disease is repellent to a prospective patient, not
to a doctor or bacteriologist; the idea of dirt is objectionable to a
housewife, but it is only matter out of place; the word 'poison'
conveys nothing objectionable to a chemist. Everything removed
from the emotional arena, and transplanted into the intellectual,
becomes interesting and tractable and worthy of study. Living
organisms of every kind are good in themselves, though when out of
place and beyond control they may be harmful. A tiger is an object
of dread to an Indian village: to a hunting party he may be keenly
attractive. In any case he is a lithe and beautiful and splendid
creature. Microscopic organisms may have troublesome and
destructive effects, but in themselves they can be studied with
interest and avidity. All living creatures have their assuredly useful
function, only it may be a function on which we naturally shrink from
dwelling when in an emotional mood. Everything of this kind is an
affair of mood; and, properly regarded, nothing in nature is common
or unclean. That a flying albatross is a beautiful object every one can
cordially admit, but that the crawling surface of a stagnant sea can
be regarded with friendly eyes seems an absurdity; yet there is
nothing absurd in it. It is surely the bare truth concerning all living
creatures of every grade, that "the Lord God made them all"; and it
was of creeping water-snakes that the stricken Mariner at length,
when he had learnt the lesson, ejaculated:—
"O happy living things!
A spring of love gushed from my heart,
And I blessed them unaware."

For what can be said poetically about the fate of the beloved body,
the poets themselves must be appealed to. But that there is kinship
between the body and the earth is literal truth. Of terrestrial
particles it is wholly composed, and that they should be restored to
the earth whence they were borrowed is natural and peaceful.
Moreover, out of the same earth, and by aid of the very same
particles, other helpful forms of life may arise; and though there may
be no conscious unification or real identity, yet it is pardonable to
associate, in an imaginative and poetic mood, the past and future
forms assumed by the particles:—

"Lay her i' the earth;—


And from her fair and unpolluted flesh,
May violets spring!"

Quotations are hardly necessary to show that this idea runs through
all poetry. An ancient variety is enshrined in the Hyacinthus and
Adonis legends. From spilt blood an inscribed lily springs, in the one
tale; and the other we may quote in Shakespeare's version (Venus
and Adonis):—

"And in his blood that on the ground lay spilled,


A purple flower sprung up chequered with white,
Resembling well his pale cheeks and the blood
Which in round drops upon their whiteness stood."

So also Tennyson:—
"And from his ashes may be made
The violet of his native land."
In Memoriam

We find the same idea again, I suppose, in the eastern original of


Fitzgerald's well-known stanza:—

"And this delightful Herb whose tender Green


Fledges the River's Lip on which we lean—
Ah, lean upon it lightly! for who knows
From what once lovely Lip it springs unseen!"

The soil of a garden is a veritable charnel-house of vegetable and


animal matter, and from one point of view represents death and
decay, but the coltsfoot covering an abandoned heap of refuse, or
the briar growing amid ruin, shows that Nature only needs time to
make it all beautiful again. Let us think of the body as transmuted,
not as stored.
The visible shape of the body was no accident, it corresponded to a
reality, for it was caused by the indwelling vivifying essence; and
affection entwines itself inevitably round not only the true
personality of the departed, but round its material vehicle also—the
sign and symbol of so much beauty, so much love. Symbols appeal
to the heart of humanity, and anything cherished and honoured
becomes in itself a thing of intrinsic value, which cannot be regarded
with indifference. The old and tattered colours of a regiment, for
which men have laid down their lives—though replaced perhaps by
something newer and more durable—cannot be relegated to
obscurity without a pang. And any sensitive or sympathetic person,
contemplating such relics hereafter, may feel some echo of the
feeling with which they were regarded, and may become acquainted
with their history and the scenes through which they have passed.
In such cases the kind of knowledge to be gained from the relic, and
the means by which additional information can be acquired, are
intelligible; but in other cases also information can be attained,
though by means at present not understood. It may sound
superstitious, but it is a matter of actual experience, that some
sensitives have intuitive perception, of an unfamiliar kind, concerning
the history and personal associations of relics or fragments or
personal belongings. The faculty is called psychometry; and it is no
more intelligible, although no less well-evidenced, than the possibly
allied faculty of dowsing or so-called water-divining. Psychometry is
a large subject on which much has already been written: this brief
mention must here suffice.
It seems to me that these facts, when at length properly
understood, will throw some light on the connexion between mind
and matter; and then many another obscure region of semi-science
and semi-superstition will be illuminated. At present in all such tracts
we have to walk warily, for the ground is uneven and insecure; and
it is better, or at least safer, for the majority to forgo the recognition
of some truth than rashly to invade a district full of entanglements
and pitfalls.

Transition
Longfellow's line, "There is no death; what seems so is transition," at
once suggests itself. Read literally the first half of this sentence is
obviously untrue, but in the sense intended, and as a whole, the
statement is true enough. There is no extinction, and the change
called death is the entrance to a new condition of existence—what
may be called a new life.
Yet life itself is continuous, and the conditions of the whole of
existence remain precisely as before. Circumstances have changed
for the individual, but only in the sense that he is now aware of a
different group of facts. The change of surroundings is a subjective
one. The facts were of course there, all the time, as the stars are
there in the daytime; but they were out of our ken. Now these come
into our ken, and others fade into memory.
The Universe is one, not two. Literally there is no 'other' world—
except in the limited and partial sense of other planets—the Universe
is one. We exist in it continuously all the time; sometimes conscious
in one way, sometimes conscious in another; sometimes aware of a
group of facts on one side of a partition, sometimes aware of
another group, on the other side. But the partition is a subjective
one; we are all one family all the time, so long as the link of
affection is not broken. And for those who believe in prayer at all to
cease from praying for the welfare of their friends because they are
materially inaccessible—though perhaps spiritually more accessible
than before—is to succumb unduly to the residual evil of past
ecclesiastical abuses, and to lose an opportunity of happy service.

Footnotes
[35] It is rash to condemn a human custom which has
prevailed for centuries or millenniums, and it is wrong to
treat it de haut en bas. I would not be understood as doing
so, in this brief and inadequate reference to the contents of
Egyptian tombs. Their fuller interpretation awaits the labour
of students now working at them.
In the same spirit I wish to leave open the question of what
possible rational interpretation may be given to the mediæval
phrase "Resurrection of the body"; a subject on which much
has been written. What I am contending against is not the
scholarly but the popular interpretation. For further remarks
on this subject see Chapter VII below.
CHAPTER IV
CONTINUED EXISTENCE

Difficulty of Belief in Continued Existence


"Sit down before fact as a little child, be prepared to give up every
preconceived notion, follow humbly wherever and to whatsoever
abysses Nature leads."—Huxley.

P EOPLE often feel a notable difficulty in believing in the reality of


continued existence. Very likely it is difficult to believe or to
realise existence in what is sometimes called "the next world"; but
then, when we come to think of it, it is difficult to believe in
existence in this world too; it is difficult to believe in existence at all.
The whole problem of existence is a puzzling one. It could by no
means have been predicated a priori. The whole thing is a question
of experience; that is, of evidence. We know by experience that
things actually do exist; though how they came into being, and what
they are all for, and what consequences they have, is more than we
can tell. We have no reason for asserting that the kind we are
familiar with is the only kind of existence possible, unless we choose
to assert it on the ground that we have no experience of any other.
But that is becoming just the question at issue: have we any
evidence, either direct or indirect, for any other existence than this?
If we have, it is futile to cite in opposition to it the difficulty of
believing in the reality of such an existence; we surely ought to be
guided by facts.
At this stage in the history of the human race few facts of science
are better established and more widely appreciated than the main
facts of Astronomy: a general acquaintance with the sizes and
distances, and the enormous number, of the solar systems
distributed throughout space is prevalent. Yet to the imaginative
human mind the facts, if really grasped, are overwhelming and
incredible.
The sun a million times bigger than the earth; Arcturus a hundred
times bigger than the sun, and so distant that light has taken two
centuries to come, though travelling at a rate able to carry it to New
York and back in less than the twentieth part of a second,—facts like
these are commonplaces of the nursery; but even as bare facts they
are appalling.
That the earth is a speck invisible from any one of the stars, that we
are on a world which is but one among an innumerable multitude of
others, ought to make us realise the utter triviality of any view of
existence based upon familiarity with street and train and office,
ought to give us some sense of proportion between everyday
experience and ultimate reality. Even the portentous struggle in
which Europe is engaged—

"What is it all but a trouble of ants


in the gleam of a million million of suns?"

Yet, for true interpretation, the infinite worth and vital importance of
each individual human soul must be apprehended too. And that is
another momentous fact, which, so far from restricting the
potentialities of existence, by implication still further enlarges them.
The multiplicity, the many-sidedness, the magnificence, of material
existence does not dwarf the human soul; far otherwise: it illumines
and expands the stage upon which the human drama is being
played, and ought to make us ready to perceive how far greater still
may be the possibilities—nay, the actualities—before it, in its infinite
unending progress.
That we know little about such possibilities as yet, proves nothing;—
for mark how easy it would have been to be ignorant of the
existence of all the visible worlds and myriad modes of being in
space. Not until the business of the day is over, and our great star
has eclipsed itself behind the earth, not until the serener period of
night, does the grandeur of the material universe force itself upon
our attention. And, even then, let there be but a slight permanent
thickening of our atmosphere, and we should have had no revelation
of any world other than our own. Under those conditions—so barely
escaped from—how wretchedly meagre and limited would have been
our conception of the Universe! Aye, and, unless we foolishly
imagine that our circumstances are such as to have already given us
a clue to every kind of possible existence, I venture to say that
"wretchedly meagre and limited" must be a true description of our
conception of the Universe, even now,—even of the conception of
those who have permitted themselves, with least hesitation, to
follow whithersoever facts lead.
If there be any group of scientific or historical or literary students
who advocate what they think to be a sensible, but what I regard as
a purblind, view of existence, based upon already systematised
knowledge and on unfounded and restricting speculation as to
probable boundaries and limitations of existence,—if such students
take their own horizon to be the measure of all things,—the fact is to
be deplored. Such workers, however admirable their industry and
detailed achievements, represent a school of thought against the
fruits of which we of the Allied Nations are in arms.
Nevertheless speculation of this illegitimate and negative kind is not
unknown among us. It originates partly in admiration for the
successful labours of a bygone generation in clearing away a
quantity of clinging parasitic growth which was obscuring the fair
fabric of ascertained truth, and partly in an innate iconoclastic
enthusiasm.
The success which has attended Darwinian and other hypotheses
has had a tendency to lead men—not indeed men of Darwinian
calibre, but smaller and less conscientious men—in science as well
as in history and theology, to an over-eager confidence in probable
conjecture and inadequate attention to facts of experience. It has
even been said—I quote from a writer in the volume Darwin and
Modern Science, published in connexion with a Darwin jubilee
celebration at Cambridge—that "the age of materialism was the least
matter-of-fact age conceivable, and the age of science the age which
showed least of the patient temper of enquiry." I would not go so far
as this myself, the statement savours of exaggeration, but there is a
regrettable tendency in surviving materialistic quarters for
combatants to entrench themselves in dogma and preconceived
opinion, to regard these vulnerable shelters as sufficient protection
against observed and recorded facts, and even to employ them as
strongholds from which alien observation-posts can be shattered and
overthrown.
CHAPTER V
PAST, PRESENT, AND FUTURE

"How often have men thus feared that Nature's wonders would be
degraded by being closelier looked into! How often, again, have they
learnt that the truth was higher than their imagination; and that it is
man's work, but never Nature's, which to be magnificent must
remain unknown!"—F. W. H. M., Introduction to Phantasms of the
Living

O UR actual experience is strangely limited. We cannot be actually


conscious of more than a single instant of time. The momentary
flash which we call the present, the visual image of which can be
made permanent by the snap of a camera, is all of the external
world that we directly apprehended. But our real existence embraces
far more than that. The present, alone and isolated, would be
meaningless to us; we look before and after. Our memories are
thronged with the past; our anticipations range over the future; and
it is in the past and the future that we really live. It is so even with
the higher animals: they too order their lives by memory and
anticipation. It is under the influence of the future that the animal
world performs even the most trivial conscious acts. We eat, we rest,
we work, all with an eye to the immediate future. The present
moment is illuminated and made significant, is controlled and
dominated, by experience of the past and by expectation of the
future. Without any idea of the future our existence would be purely
mechanical and meaningless: with too little eye to the future—a
mere living from hand to mouth—it becomes monotonous and dull.
Hence it is right that humanity, transcending merely animal scope,
should seek to answer questions concerning its origin and destiny,
and should regard with intense interest every clue to the problems
of 'whence' and 'whither.'
It is no doubt possible, as always, to overstep the happy mean, and
by absorption in and premature concern with future interests to lose
the benefit and the training of this present life. But although we may
rightly decide to live with full vigour in the present, and do our duty
from moment to moment, yet in order to be full-flavoured and really
intelligent beings—not merely with mechanical drift following the line
of least resistance—we ought to be aware that there is a future,—a
future determined to some extent by action in the present; and it is
only reasonable that we should seek to ascertain, roughly and
approximately, what sort of future it is likely to be.
Inquiry into survival, and into the kind of experience through which
we shall all certainly have to go in a few years, is therefore
eminently sane, and may be vitally significant. It may colour all our
actions, and give a vivid meaning both to human history and to
personal experience.
If death is not extinction, then on the other side of dissolution
mental activity must continue, and must be interacting with other
mental activity. For the fact of telepathy proves that bodily organs
are not absolutely essential to communication of ideas. Mind turns
out to be able to act directly on mind, and stimulate it into response
by other than material means. Thought does not belong to the
material region: although it is able to exert an influence on that
region through mechanism provided by vitality. Yet the means
whereby it accomplishes the feat are essentially unknown, and the
fact that such interaction is possible would be strange and surprising
if we were not too much accustomed to it. It is reasonable to
suppose that the mind can be more at home, and more directly and
more exuberantly active, where the need for such interaction
between psychical and physical—or let us more safely and
specifically say between mental and material—no longer exists,
when the restraining influence of brain and nerve mechanism is
removed, and when some of the limitations connected with bodily
location in space are ended.
Experience must be our guide. To shut the door on actual
observation and experiment in this particular region, because of
preconceived ideas and obstinate prejudices, is an attitude common
enough, even among scientific men; but it is an attitude markedly
unscientific. Certain people have decided that inquiry into the
activities of discarnate mind is futile; some few consider it impious;
many, perhaps wisely mistrusting their own powers, shrink from
entering on such an inquiry. But if there are any facts to be
ascertained, it must be the duty of some volunteers to try to
ascertain them: and for people having any acquaintance with
scientific history to shut their eyes to facts when definitely
announced, and to forbid investigation or report concerning them on
pain of ostracism,—is to imitate a bygone theological attitude in a
spirit of unintended flattery—a flattery which from every point of
view is eccentric; and likewise to display an extraordinary lack of
humour.

On the Possibility of Prognostication


I do not wish to complicate the issue at present by introducing the
idea of prognostication or prevision, for I do not understand how
anticipation of the future is possible. It is only known to be possible
by one of two processes—
(a) Inference—i.e. deduction from a wide knowledge of the
present;
(b) Planning—i.e. the carrying out of a prearranged scheme.
And these methods must be pressed to the utmost before admitting
any other hypothesis.
As to the possibility of prevision in general, I do not dogmatise, nor
have I a theory wherewith to explain every instance; but I keep an
open mind and try to collate and contemplate the facts.
Scientific prediction is familiar enough; science is always either
historic or prophetic (as Dr. Schuster said at Manchester in the
British Association Address for 1915), "and history is only prophecy
pursued in the negative direction." This thesis is worth illustrating:—
That Eclipses can be calculated forwards or backwards is well
known. A tide-calculating machine, again, which is used to churn out
tidal detail in advance by turning a handle, could be as easily run
backwards and give past tides if they were wanted; but always on
the assumption that no catastrophe, no unforeseen contingency,
nothing outside the limits of the data, occurs to interfere with the
placid course of phenomena. There must be no dredging or harbour
bar operations, for instance, if the tide machine is to be depended
on. Free-will is not allowed for, in Astronomy or Physics; nor any
interference by living agents.
The real truth is that, except for unforeseen contingencies, past,
present, and future are welded together in a coherent whole; and to
a mind with wider purview, to whom perhaps hardly anything is
unforeseen, there may be possibilities of inference to an
unsuspected extent. Human character, and action based upon it,
may be more trustworthy and uncapricious than is usually supposed;
and data depending on humanity may be included in a completer
scheme of foreknowledge, without the exercise of any compulsion.
"The past," says Bertrand Russell eloquently, "does not change or
strive; like Duncan, after life's fitful fever it sleeps well; what was
eager and grasping, what was petty and transitory, has faded away;
the things that were beautiful and eternal shine out of it like stars in
the night." My ignorance will not allow me to attempt to compose a
similar or rather a contrasting sentence about the future.

Reference to Special Cases


It will be observed that none of those indications or intimations
or intuitions which are referred to in a note on page 34, Part I, if
they mean anything, raise the difficult question of prevision. In
every case the impression was felt after or at the time of the
event, though before reception of the news. The only question
of possible prevision in the present instance arises in connexion
with the 'Faunus' message quoted and discussed in Part II. But
even here nothing more than kindly provision, in case anything
untoward should happen, need be definitely assumed. Moreover,
if the concurrence in time suggests prognostication, the fact
that a formidable attempt to advance the English Front at the
Ypres salient was probably in prospect in August 1915, though
not known to ordinary people in England, and not fully carried
out till well on in September, must have been within human
knowledge; and so would have to be considered telepathically
accessible, if that hypothesis is considered preferable to the
admission of what Tennyson speaks of as—

"Such refraction of events


As often rises ere they rise."

Prognostication can hardly be part of the evidence for survival.


The two things are not essential to each other; they hardly
appear to be connected. But one knows too little about the
whole thing to be sure even of this, and I decline to take the
responsibility for suppressing any of the facts. I know that Mr.
Myers used to express an opinion that certain kinds of prevision
would constitute clear and satisfactory evidence of something
supernormal, and so attract attention; though the establishment
of such a possibility might tend to suggest a kind of higher
knowledge, not far short of what might be popularly called
omniscience, rather than of merely human survival.

You might also like