Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
100% found this document useful (4 votes)
46 views

Complete Download How JavaScript Works: Master the Basics of JavaScript and Modern Web App Development 1st Edition Jonathon Simpson PDF All Chapters

Web

Uploaded by

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

Complete Download How JavaScript Works: Master the Basics of JavaScript and Modern Web App Development 1st Edition Jonathon Simpson PDF All Chapters

Web

Uploaded by

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

Experience Seamless Full Ebook Downloads for Every Genre at ebookmeta.

com

How JavaScript Works: Master the Basics of


JavaScript and Modern Web App Development 1st
Edition Jonathon Simpson

https://ebookmeta.com/product/how-javascript-works-master-
the-basics-of-javascript-and-modern-web-app-development-1st-
edition-jonathon-simpson-2/

OR CLICK BUTTON

DOWNLOAD NOW

Explore and download more ebook at https://ebookmeta.com


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

How JavaScript Works: Master the Basics of JavaScript and


Modern Web App Development 1st Edition Jonathon Simpson

https://ebookmeta.com/product/how-javascript-works-master-the-basics-
of-javascript-and-modern-web-app-development-1st-edition-jonathon-
simpson/
ebookmeta.com

The Modern Web Multi Device Web Development with HTML5


CSS3 and JavaScript 1st Edition Gasston Peter

https://ebookmeta.com/product/the-modern-web-multi-device-web-
development-with-html5-css3-and-javascript-1st-edition-gasston-peter/

ebookmeta.com

JavaScript for Modern Web Development Building a Web


Application Using HTML CSS and Javascript 1st Edition Alok
Ranjan Abhilasha Sinha Ranjit Battewad
https://ebookmeta.com/product/javascript-for-modern-web-development-
building-a-web-application-using-html-css-and-javascript-1st-edition-
alok-ranjan-abhilasha-sinha-ranjit-battewad/
ebookmeta.com

Blender 2D Animation: The Complete Guide to the Grease


Pencil 1st Edition John M. Blain

https://ebookmeta.com/product/blender-2d-animation-the-complete-guide-
to-the-grease-pencil-1st-edition-john-m-blain/

ebookmeta.com
Actionable Research for Educational Equity and Social
Justice Higher Education Reform in China and Beyond 1st
Edition Wang Chen (Editor)
https://ebookmeta.com/product/actionable-research-for-educational-
equity-and-social-justice-higher-education-reform-in-china-and-
beyond-1st-edition-wang-chen-editor/
ebookmeta.com

The Manor House Governess A Novel 1st Edition C A Castle

https://ebookmeta.com/product/the-manor-house-governess-a-novel-1st-
edition-c-a-castle/

ebookmeta.com

Absolute Breast Imaging Review Multimodality Cases for the


Core Exam Lucy Chow Editor Bo Li Editor

https://ebookmeta.com/product/absolute-breast-imaging-review-
multimodality-cases-for-the-core-exam-lucy-chow-editor-bo-li-editor/

ebookmeta.com

Multifunctionality in English: Corpora, Language and


Academic Literacy Pedagogy 1st Edition Zihan Yin (Editor)

https://ebookmeta.com/product/multifunctionality-in-english-corpora-
language-and-academic-literacy-pedagogy-1st-edition-zihan-yin-editor/

ebookmeta.com

The Liar’s Crown (Dominions Book 1) Abigail Owen

https://ebookmeta.com/product/the-liars-crown-dominions-
book-1-abigail-owen/

ebookmeta.com
Cybersecurity Awareness Jerry Andriessen

https://ebookmeta.com/product/cybersecurity-awareness-jerry-
andriessen/

ebookmeta.com
Jonathon Simpson

How JavaScript Works


Master the Basics of JavaScript and Modern
Web App Development
Jonathon Simpson
Belfast, Antrim, UK

ISBN 978-1-4842-9737-7 e-ISBN 978-1-4842-9738-4


https://doi.org/10.1007/978-1-4842-9738-4

© Jonathon Simpson 2023

This work is subject to copyright. All rights are solely and exclusively
licensed by the Publisher, whether the whole or part of the material is
concerned, specifically the rights of translation, reprinting, reuse of
illustrations, recitation, broadcasting, reproduction on microfilms or in
any other physical way, and transmission or information storage and
retrieval, electronic adaptation, computer software, or by similar or
dissimilar methodology now known or hereafter developed.

The use of general descriptive names, registered names, trademarks,


service marks, etc. in this publication does not imply, even in the
absence of a specific statement, that such names are exempt from the
relevant protective laws and regulations and therefore free for general
use.

The publisher, the authors, and the editors are safe to assume that the
advice and information in this book are believed to be true and accurate
at the date of publication. Neither the publisher nor the authors or the
editors give a warranty, expressed or implied, with respect to the
material contained herein or for any errors or omissions that may have
been made. The publisher remains neutral with regard to jurisdictional
claims in published maps and institutional affiliations.

This Apress imprint is published by the registered company APress


Media, LLC, part of Springer Nature.
The registered company address is: 1 New York Plaza, New York, NY
10004, U.S.A.
Introduction
JavaScript is one of the most used programming languages in the world.
When JavaScript was first created, it was a useful tool for adding
interactivity to web pages. Since then, it has evolved to power back-end
servers, massive front-end web applications, and even iPhone and
Android applications via tools like Electron and Tauri.
While JavaScript has matured as a language its complexity seems to
have increased. What started as simple scripts inside HTML tags now
seems to involve compile steps via TypeScript and frameworks like
React, Vue.js, or Svelte. For those getting started in JavaScript, it can be
overwhelming, even though these tools are just an additional level of
abstraction which ultimately compiles down into vanilla JavaScript.
In this book, we’ll learn how JavaScript works from the bottom up,
which will prepare you for everything web development and JavaScript-
led app development can throw at you. We’ll also explain some of the
quirks you’ll find in JavaScript and how many of them have come to be
due to JavaScript’s long and varied history.
After that, we’ll cover JavaScript’s unique approach to inheritance
before moving into more complicated topics like memory management,
classes, APIs, and web workers. We’ll explore how the weakly typed
system JavaScript employs has both benefits and downsides.
As a fundamental part of the web stack, and with more people using
it every day, there has never been a better time to learn JavaScript. This
book will guide you through everything you need to know, so that you
can master modern web app development.
Table of Contents
Chapter 1:​Introduction to JavaScript
JavaScript Fundamentals
JavaScript’s Type Classification
What Is JavaScript Used For?​
Writing JavaScript
Summary
Chapter 2:​Code Structure and Logical Statements
Getting Started
Common Code Conventions
Semicolons
Spacing
Variable and Function Naming
JavaScript Variables
Setting Variables with let
Setting Variables with var
Setting Variables with const
Defining Variables Without Values
Assignment Operators
Variable Concatenation
JavaScript Comments
Logical Statements
If…else Statements
Switch Statements
Block Scoping with Logical Statements
Conditional Operator in Variables
Logical Statement Comparison Operators
Logical Statement Logical Operators
Summary
Chapter 3:​Introduction to Objects, Arrays
Arrays
Getting the Length of an Array
Getting the Last Element of an Array
Array Manipulation Methods
Push and Unshift
Pop and Shift
Splice
Objects
Accessing Object Data
Object Mutability
Spread Syntax or the “Three Dots”
Prototype-Based Programming
Prototypical Inheritance
[[Prototype]] vs.​prototype (and _​_​proto_​_​)
Object Shallow and Deep Copies
Summary
Chapter 4:​Loops and Iterables
Loops
Break and Continue in Loops
Loop Labels
Iteration
Iterables and For Loops
Array forEach methods
String Iteration
Iteration Protocol
Objects Are Not Iterable by Default
Summary
Chapter 5:​References, Values, and Memory Management
Introduction
Stacks
The Event Loop
The Heap
Object and Reference Equality
Summary
Chapter 6:​Functions and Classes
Introduction to Functions
Running Arguments with the “Three Dots”
Alternative Ways to Call Functions
Unnamed Function Expressions
Anonymous Functions
Functions with Arrow Notation
Functions and the “this” Keyword
Sloppy Mode
Arrow Notation Functionality with this
Calling Functions with Context
Constructor Functions in JavaScript
Additional Function Methods
Getters and Setters
Generator Functions
Classes
Classes and Constructor Functions
Class Methods
Class Method Types
Class Inheritance via Extends
Summary
Chapter 7:​Types
Primitive Types
Primitive Wrappers
Using Wrappers to Create Types
The Number Type and NaN
Number Type Mathematics
Mathematical Methods
The Date Type
The Symbol Type
Truthy and Falsy Types
Truthy and Falsy Operators
Logical AND Operator
Logical OR Operator
Nullish Coalescing
Optionality
Summary
Chapter 8:​Manipulating and Interacting with HTML
Window and Document Objects
The Window Object
The Document Object Model
Selecting HTML Elements
The Order of HTML
NodeLists and HTMLCollections
Manipulating HTML After Selection
Adding Events to HTML Elements
Creating a Modal Window
Creating a Counter
Event Types
Drag and Drop
The e variable
Creating New Elements with JavaScript
Manipulating CSS with JavaScript
HTMLElements and Changing Styles in JavaScript
Adding New Style Sheets to HTML Pages
Setting CSS Variables
Getting CSS Properties and HTML Dimensions
Summary
Chapter 9:​Maps and Sets
Sets
Modifying Sets
Checking Set Membership
Checking Set Size
Merging Sets
Set Iteration and Values
Maps
Retrieving Map Properties
Checking for Key Existence on a Map
Telling How Big a Javascript Map Is
Iterating, Merging, and Accessing Maps
Keys and Values in Maps
Serialization of Maps in JavaScript
Summary
Chapter 10:​Fetching Data, APIs, and Promises
What Are APIs?​
Understanding HTTP
RESTful Design
Understanding APIs Through a Node.​JS Web Server
Testing Endpoints with Postman
The Benefits of APIs
Sending Data to APIs with JSON
The fetch Function
A Deep Dive into Fetch Options
Asynchronicity and Promises
Promise Methods:​then, finally, and catch
The await Keyword
Useful Promise Methods
Summary
Chapter 11:​Introduction to Web APIs
Web APIs
Frequently Used Web APIs
URL API
Web Storage API
Web Notifications API
History API
Summary
Chapter 12:​Errors and the Console
The Console Object
Console Errors, Debugs, Warnings, and Info
Console Timing
Console Counting
Other Useful Console Methods
Console Grouping
Console Tables
Errors and Exceptions
try…catch
Generating Errors
Handling Specific Errors
Summary
Chapter 13:​The Canvas
Introduction
Drawing and Images
Drawing Rectangles
Drawing Circles
Drawing Triangles
Drawing Images
Drawing Text
Interactivity and Creating a Drawing Application
Animations
Summary
Chapter 14:​Web Workers and Multithreading
Introduction
Using Web Workers
Sending Messages to and from Web Workers
Restrictions on Web Workers
Conclusion
Index
About the Author
Jonathon Simpson
studied at UCL and currently works in product development at Revolut,
a global neobank and financial technology company that offers banking
services. He has over 15 years of web development experience working
on a wide range of products and services. Jonathon also owns and
operates a popular software engineering blog focusing on JavaScript
and web development.
About the Technical Reviewer
Russ Ferguson
is a web application developer living in Brooklyn, New York. He has
worked on projects for organizations such as Ann Taylor, MTV, DC
Comics, and LG. Currently, he is the Vice President at Bank of America
managing a team of Angular developers, building internal applications.
Another Random Document on
Scribd Without Any Related Topics
There was no fear of any fire following them into the clearing, for
nothing remained there upon which it could feed. It took another direction,
more to the north-west, and the men and boy were safe.

With noisy jests and much jeering at the fears which now were over the
company made their way to the deserted camp of the lumberers. This
proved to be a big frame-building, run up for the temporary convenience of
the men who felled the trees, and then deserted when their work was done
and the timber conveyed away. All round the inside of the building were
sleeping-bunks, half filled still with dry grass and ferns.

They set to work with alacrity to kindle a fire, make coffee, cook some
meat, and spread out their biscuits.

No one took any notice of Cyril, who stood in a corner watching them
furtively. What powerful men they were! And how wicked some of them
looked! But others seemed quite pleasant and kind. He watched Whiterock
closely with very mingled feelings. He would have been most grateful to
him for saving his life if it were not for the strong suspicion he had that he
was the very man who had attacked his father. At that time he wore a mask.
Now his dark-bearded face was uncovered. But there was something in his
build and manner, and especially in the tones of his voice, which made
Cyril confident that he was his poor father's assailant. How the boy longed
to ask him if he had left his father living still! Would he be very angry if he
were asked the question?

"Whiterock!" Cyril called timidly to him, stealing nearer as he did so.

The man had constituted himself cook, and was stooping over a battered
frying-pan, whereon spluttered great slices of meat. Being much absorbed
in his cooking he only noticed Cyril's call by giving him a nod.

Cyril did not return the nod. For just as he was about to do so it occurred
to him that if the man were really his poor father's cruel assailant he could
return no greeting of his.

Whiterock did not notice the boy's lack of cordiality; he was talking to
one of the stewards now about the meat, which had run short. There would
not be sufficient to go round. This was a great difficulty which could not be
got over by talking.

When at last the men sat and lay down in a sort of circle round the
stewards, who helped out the food straight from two central dishes into the
men's hands, Cyril was called up by Whiterock and received a share of
biscuit only.

"Biscuit is good enough for bairns," said the steward, laughing.

But Whiterock, grumbling, thrust a small piece of meat upon the boy's
biscuit. It was his own. But how could Cyril eat it? He pushed it back into
the man's hand. Whiterock looked annoyed, and made no further attempt to
improve his meal. The men drank their coffee out of little cups belonging to
their flasks. Cyril had not one, so would have had to go without if the
steward had not kindly lent him his.

After the breakfast all the men but two or three, who remained to look
after the horses, collect wood, and so forth, went off on foot to hunt. They
returned, late in the afternoon, with an immense quantity of game. The men
who had not been hunting were sent, with a couple of horses, to fetch home
some of the best parts of the deer which the others had shot.

There was a great feast that evening, and much work afterwards in
cutting and hanging up strips of meat to be smoked and dried by the fire
during the night. Then the men divided the sleeping-bunks. Cyril shared one
with Whiterock.

"There, get in, youngster," said Whiterock. "I'm awful sleepy. Want to
say something? No, I can't hear it to-night. To-morrow some time will do.
Good-night." He fell asleep, or appeared to do so, almost as he spoke.

Cyril dared not disturb him to inquire about his father's fate. He, too, was
very sleepy, and in spite of his anxiety speedily followed his companion's
example.

He was awoke suddenly in the night by shouts from the men, and then
much loud talking and exclaiming. What was the matter? The men were
flying wildly out of their bunks, on all sides, and making for the door. At
that moment something soft, smooth, and slippery wound itself round
Cyril's neck. With a cry for help he caught hold of Whiterock's hand.

The man sat up and astonished the boy by laughing loudly.

CHAPTER IV.

TEMPTED.

Whiterock flung something from the boy, and, jumping out of the bunk,
still laughing loudly, lifted him on to the ground.

"Captain," he called out, "these old bunks here are full of pine-snakes,
which have crawled into them for warmth. Fortunately they are quite
harmless. Now then, men, they won't hurt you!"

When all the men had returned they declared that it was impossible to
sleep any more that night. So more coffee was made, and they all sat and
lay about near the fire, talking of their future plans. Cyril began to count the
men, but was still so sleepy that he could not quite decide whether their
number was nearer twenty than thirty.

For some time no one took any notice of the boy. But at last the Captain
did so, and jeered at Whiterock for turning nursemaid.

Then they all began to talk of Cyril, much to his discomfiture.

Presently Whiterock asked him if he would like to remain with them as


his adopted son, and in time would become one of the band.

"Ah, like Wolfgang," said the Captain, stroking his long beard. "He was
a lad of about your age. We found him. I won't say where, but he grew up
amongst us, and for cleverness and pluck there wasn't a man of us all that
could beat him. Ah, he would have been captain if he had lived! He was
killed in a scuffle with the police. He died fighting nobly."

Cyril had his own opinion about the nobleness of fighting the public
officers of law and order. But he felt sorry for Wolfgang. The lad probably
knew no better.

"Well, little 'un," said Whiterock, "would you like to stay with us and be
my boy?"

"But my father?" said Cyril tremulously, looking appealingly at him.

"Oh, he's dead," said Whiterock hastily. "Now come, boy, don't make a
scene."

Cyril turned his back on him. He was struggling with all his might to
keep back the tears which would not be suppressed. His father, his dear,
kind father, slain by that coarse, ruffianly fellow! Oh, it was too cruel!

"What's the matter?" demanded the Captain.

Whiterock crossed over to him, and said something rather low in his ear.

"Oh!" cried the Captain. "But that's only the fortune of war. Come here,
my boy," he added to Cyril.

Cyril went up to him with a pale, resolute face.

"Whiterock saved your life, lad," said the Captain. "You must remember
that. There wasn't one of us who would have done so much for you at such
a time."

"He took my father's life," replied Cyril, looking up with flashing eyes,
the hot blood mounting to his very brow.

"But he saved your life, lad," remonstrated the Captain.


"I know he saved my life," cried Cyril, "and I just wish he hadn't! As he
killed my father, I would rather have died than——"

"Be quiet!" thundered the Captain. "Will you stay with us or no?"

"No, a thousand times no!" answered the boy boldly.

"I won't have him," muttered Whiterock sulkily.

"But I will," cried the Captain. "Look here, my lad, I honour you. Yes, I
honour you for loving and respecting your father. You're a plucky lad! And
if you like to stay with us you shall be my adopted son. Do you hear what I
say?"

The men uttered various exclamations, tending to show that what they
considered "a piece of rare luck" had come in Cyril's way.

Then they all waited for the boy's answer.

"No, thank you, Captain," he said politely, "I cannot."

"What for, lad? Why not?" demanded the Captain wrathfully.

"Oh, because 'Noblesse oblige!'" replied the boy.

"What do you say?"

Cyril repeated "Noblesse oblige" distinctly, in tones which were heard all
over the great room.

"How do you explain those words?" asked the Captain.

"Oh, don't you understand them?" said Cyril, surprised that such a great
man as the Captain should be ignorant of their meaning. "My father"—his
voice shook a little as he said the name—"told me Noblesse oblige means
rank imposes obligations, and that much is expected from one in a good
position. You see, Captain, gentlemen can't do mean, dishonourable things.
I'm sorry to disappoint you, but you see I come of a race of honourable
gentlemen who would scorn to rob and plunder."
The Captain laughed loudly, rudely. "What a fine gentleman we've got
here!" said he; "let's look at him." He dragged Cyril forward into the middle
of the room. "There, my fine fellow, look around you," cried he. "Do you
know several of these men are gentlemen of birth and breeding?"

"Then they've forgotten it," said Cyril calmly.

A murmur of anger went round the room. "Forgotten what?" cried one
man.

"Noblesse oblige," replied Cyril.

"Absurd," cried the Captain. "Have you no better reason than that for
refusing my offer?"

Cyril was silent.

"Speak out," cried the Captain.

Slowly but bravely Cyril said that there was yet another reason. He could
not join them because he was a follower of Christ, who made the law of
love, saying, "By this shall all men know that ye are My disciples, if ye have
love one to another."

A cry of rage burst from most of the men upon hearing this. But one or
two drew rough hands across their faces, as if to hide them for a moment.

CHAPTER V.

CYRIL'S SENTENCE.

"You little prig!" sneered the Captain of the band. But he did not look at
Cyril. "Preaching at us!" cried another man indignantly.
"He wants taking down a peg or two," said a third.

"What sinners we must be!" scoffed a fourth.

"Leave him alone," growled one whose heart the boy's brave, noble
words had touched. "Let him be."

"Aye, do," said a younger man. But he spoke timidly, looking down on
the ground as he did so. "In case—in case," he added, "the youngster may
be right."

"Right! Hark at him! Hark at Green!" jeered two or three rough voices.

The Captain looked angrily around at the men, and then at the boy. He
felt thoroughly out of temper.

"A good thrashing would do the lad no harm," he muttered.

"Thrashing's too good for him," grumbled Whiterock, all his kind feeling
for Cyril having changed to bitter dislike.

"Boy, come here," cried the Captain.

Cyril went up to him. He was very pale now, and trembling. He did not
feel at all brave as he clasped his hands nervously together. It was terrible to
feel that he stood alone, unarmed, helpless in the midst of all these men.

The Captain looked searchingly at him. "Your name, lad?" he demanded


in stern tones.

"Cyril Morton," answered the boy.

"Cyril! A girl's name! Pooh!"

With a sudden change of mood the Captain laughed derisively. He


passed his big, rough hand over the boy's soft curly hair and down his slim
young figure.
"All the same," he said, "I like you, boy, and believe that we can make a
man of you yet. After all, I will repeat my offer. Will you stay and be my
son?"

Cyril shook his head. He could not speak at the moment, for the right
words would not come. Was he to go through the ordeal again?

"He won't!" cried one of the men indignantly. "Did you ever know such
defiance?"

"Speak," demanded the Captain, his hand resting heavily now on Cyril's
shoulder as if he would compel his obedience. "Do you still refuse?"

"Yes. I cannot—oh, I cannot accept your offer! I cannot!" cried the boy.

"Very well," shouted the Captain angrily. "You defy us! Here, you,
Whiterock, you brought the youngster. Take him outside a bit while we
decide what is to be done. Take him away, I say, for ten minutes. Then bring
him back to hear his sentence."

Cyril trembled. Would they kill him? Out here in the backwoods they
could do whatever they liked. There were no policemen here.

"Come on," said Whiterock, seizing hold of Cyril's collar and dragging
him out of the place.

Outside he flung the boy down on the ground at his feet.

"Oh, Whiterock," pleaded Cyril, "though you killed my father—my dear,


good father, will you not save me, his son?"
"Oh, Whiterock, will you not save me?"
It was the best plea the boy could have made, for since those words of
his to the Captain, and his terrible distress about his poor father, Whiterock
had felt something like compunction for what he had done.

"The matter lies in your own hands, Cyril," he said, not unkindly. "You,
and only you, can save your life. Accept the Captain's offer—it is a
generous one."

"But I can't," said Cyril. "Oh, Whiterock, I can't!"

"Well, come back with me inside."

"One moment," cried poor Cyril. "What will they do to me?"

"You'll hear that soon enough," muttered Whiterock, leading him inside
the huge shanty.

"Come here," called the Captain loudly, "and hear our decision."

Cyril stood tremblingly before him.

"It is," cried the man, "that if you do not change your mind by morning
and consent to become one of our band, we shall tie you to a bunk and leave
you here imprisoned in this camp, with only the snakes for your
companions."

A cry of horror escaped from Cyril's lips. Then eagerly, passionately, he


pleaded with the Captain to punish him in any other way he liked than that.

But to all and everything he urged the Captain had only one answer,
Cyril must accept his offer, and then all would be well with him.

The boy, however, although greatly tempted to dissemble for a while and
pretend to comply with the Captain's wishes until they reached a more
civilised place where he might gain succour, remained firm.

So did the Captain. At the break of day he and the men breakfasted
without giving one morsel of food to the boy. Then they made their
preparations for leaving the place, which consisted mainly in packing up the
best of the game and deer flesh.

When they were quite ready to start the Captain strode up to Cyril,
asking if he had changed his mind.

"No, sir," answered the boy.

Then the Captain made two of his men lay Cyril down in a bunk and tie
him to it securely.

The horrified boy, looking round nervously, perceived a snake at the foot
of the bunk, and another larger reptile at one side of it.

Was he to be left exposed to their unwelcome embraces? Harmless they


might be, but most unpleasant.

Vainly he begged and implored for mercy.

To all and everything he said the Captain's reply was always, "Do you
change your mind? Will you be one of us?"

"I cannot! Oh, I cannot!" cried the poor boy every time.

Last of all Whiterock came up, and once more advised him not to throw
his life away.

Cyril, however, would not yield.

Then they left him, and going outside mounted their horses and rode off.

There was a great silence in the deserted camp.

Cyril prayed to God for help.

Suddenly he felt a cold, slimy body slipping round his leg and gliding up
his waist. He could not reach it with his hands, which were tied to the side
of the bunk. Shouting at it to frighten it away was not of any use.
With a piercing scream he gave himself up for lost and knew no more.

CHAPTER VI.

DELIVERANCE.

"Poor little chap!" said a rough but kindly voice, as a young man
unwound the snake from Cyril's body and dashed it on the ground.
"Pluckier than any of us men after all. Here, my lad, drink this." Whilst
speaking he had unfastened Cyril's collar, and was now holding a flask to
his lips.

Opening his eyes Cyril looked with a troubled gaze into the man's
weather-beaten face. What had happened? Slowly he remembered. It was
the young man called Green, who had tried to speak up for him when the
others were so angry. What was he doing here?

Green cut away the ropes, and lifting the boy out of the bunk carried him
away from the gloomy place altogether into the sunshine outside. Then he
laid him down on some long grass, and going to his horse, which was tied
to a fence near by, got a packet of food out of his saddle-bag.

The sweet, fresh air revived Cyril; the sunshine warmed him and did him
good. In his heart he thanked God for the blessed change.

As Cyril ate and drank the repentant outlaw watched him with hungry
eyes. There had been a time once when he was an innocent boy like him.
Ah, well! that was long ago, and the good mother, whose pride and joy he
had been in those days, had been dead for many years. There was no one to
care so much what he did when she had gone, and the tempter enticed him
along the downward path of idleness and self-pleasing. He had forgotten his
mother's God, and had turned away his mind from all thoughts of Him!
That was the beginning and the end of all the evil.

But this boy, Cyril, had done very differently. Alone, unarmed, he had
been brave in the most terrible danger, he had resisted the greatest
temptation.

The robber sighed deeply.

Cyril, looking up, saw two great tears rolling down the man's face. He
turned his head away quickly lest the boy should see them.

Jumping up he threw his arms round the man's neck.

"You have saved my life," he cried, "and now you are in trouble
yourself. Yes, I know you are. Is there anything I can do? Will you—will
you tell me what is the matter?"

Deeply touched, Green sank down on the grass beside Cyril and told him
the whole story of his life, from the time when, as a child, he said his
prayers at his mother's knee to the hour when, with his companions, he
heard Cyril's outspoken condemnation of their wicked life.

"All night long," he said in conclusion—"all night long I've been


thinking, thinking as I never thought before, and I've made up my mind, lad,
that I'll try to lead a different life. If I can't earn my bread and cheese in
future—well, I'll go without it. And I'll ask God's forgiveness for all my
wrong-doing as long as I've breath in me to ask it."

After a pause, during which Green sat pondering, his horse made an
impatient movement, which reminded him that they ought to set off.

"But where shall we go?" asked Cyril wonderingly.

Green replied that his father still lived, and happened to be working in a
great saw-mill not twenty miles away from where they were. "If we go to
him," he said, "I know he will get me work to do."
Then Cyril asked if Green could put him in the way of returning to
England to his friends.

Green felt very sorry for him as he listened. But as Cyril had not nearly
enough money, and he had very little himself, he did not see how he could
possibly assist the boy to return home. However, the first thing was to get
him into a place of safety, for the robbers might return when they missed
their comrade, or possibly, relenting, they might come back to liberate
Cyril.

Mounting his horse, therefore, Green took up Cyril before him on the
saddle and rode off.

After proceeding about five miles through the forest, without any greater
adventure than the frequent difficulty of finding a path through the dense
trees, they unfortunately came out into an open sandy plain, across which
they had not gone far before they were perceived by some horsemen who
happened to be crossing the plain in another direction.

With wild cries the men turned their horses about and set off after Green
and Cyril.

It was a most unequal chase. The doubly-laden horse could not by any
chance escape the pursuers, who gained ground every moment.

Encouraging it by word and by every other means in his power Green


rode on, but with little hope in his heart.

Nearer and nearer came the pursuers, laughing and shouting as their
horses flew over the plain.

"Come, Jack! Jack, old fellow, for pity's sake!" cried Green.

Tossing his head, with flakes of foam flying from his mouth, the horse
dashed on.

But still the followers gained a little more.


"Jack, old fellow!" There was something despairing now in Green's
appeal to the animal.

Neighing loudly, as if in answer, the horse galloped even faster than


before. His hoofs scarcely seemed to touch the ground. It was all Cyril
could do to hold on to his friend.

"Stop! stop! stop, or we fire!" cried a stentorian voice.

"Jack!" Green's appeal was almost frantic now.

With a bound the horse responded, plunging forward with greater speed
than ever.

A shot rang through the air. Jack swerved heavily to one side; then he
rolled over dead.

CHAPTER VII.

A FALSE ALARM.

The good horse Jack was dead, but neither Green nor Cyril were hurt.
Fortunately for them the last violent movement of the animal threw them
quite clear of its body.

"Cowards!" exclaimed Green, rising, and looking indignantly through a


cloud of dust in the direction whence the shot had been fired.
"'Cowards!' exclaimed Green, rising, and looking indignantly."
"Why, Green! Green! They're off!" cried Cyril, who was already on his
feet. "They're off!"

"Off! Leaving us!"

Green could scarcely believe his eyes. Instead of coming up to seize


them the pursuers were galloping away.

"Oh! Look, look!" Cyril pointed in another direction.

A little company of horsemen had entered the sandy plain, and were
riding rapidly towards them.

"They've scared our enemies. Aye, but we'd better be off too," cried
Green in alarm.

"But we needn't run away from these men," said Cyril. "They are our
friends."

"Friends? Not they! I should have a bad time of it if they caught me,"
said Green. "You see, they're Government men on the look-out for train-
robbers and horse-stealers. Jack was a stolen horse. They'd make short work
once they laid hands on me. Come on, lad." He caught hold of Cyril's hand
and set off running back towards the forest.

"But, Green, stop. Let us tell them all. You are no outlaw now. You can
say you have done with all that sort of thing—that you are repentant!"
protested Cyril as they ran.

"That would make no difference. They'd punish me for what I've done
already."

Cyril could not help feeling that if he told his story to these new-comers
they would be sorry for him, and would befriend him. But he did not like to
suggest that he should separate from his companion and wait for them.

Green, however, seemed to be thinking of it "They would not believe


even you," he said. "You see, you'd be found in my company, and they
would think you were one of us."
Across the boy's mind flashed the copybook precept he had written many
a time, "A man is known by the company he keeps." And he remembered
he could give no proof that his narrative was true.

"It's impossible to keep this up," panted Green after a while. "I'm dead
beat! I can run no further."

The perspiration poured down his red face; he was thoroughly


exhausted.

"Nor can I," cried Cyril, who, although more used to running than Green,
was not in his usual health. "Let's give up."

They stopped short, and timidly, very timidly, looked round. They were
alone. Not a creature—neither horse nor man—had followed them. With the
exception of a few birds not a living thing could they see.

"Why, wherever be they?" exclaimed Green.

"Where? Where are they?" echoed Cyril.

There was no answer. Where, indeed, were their pursuers? Had the earth
swallowed them?

"Something must have made the new-comers fear to attack them after
all," said Green. "They must have been as afraid of the others as t'others
was of them! Did you ever know such a thing?"

"And we've been just as bad," said Cyril in a tone of disgust, "for we've
been running away from nobody at all!" He sat down dejectedly on a
sandhill.

"Three parties all running away from each other, without ever stopping
to look round! Well, that was mighty queer," cried Green.

"You were wrong about them being men in pursuit of you and your
friends," said Cyril.
"I was indeed. They weren't after us at all. They must have been just
quiet, peaceable travellers who heard the firing, and, being alarmed, made
off back again as fast as they could!"

"Well, they saved us, anyway," said Cyril.

"Yes, that's true enough."

"But how shall we get on without a horse?"

"Poor Jack!" sighed Green. "Captain gave him to me because I was the
means of his getting a whole lot——" he stopped abruptly. "What a rascal
I've been!" he reflected.

"I'm ravenously hungry," said Cyril.

"And we've left nearly all our food in the saddlebags. But not quite, I've
a little here!" Green got a packet out of his pocket, and, opening it,
disclosed some slices of cooked meat.

"Oh, thank you!" Cyril said, gratefully taking his share.

For a few moments they ate in silence, then Green said they must push
ahead as fast as possible before night came on.

"But which way shall we take?"

"Oh, we can't be so very far from the saw-mill where my father works, if
I could only find the way there," said Green.

However, it turned out that he really did not know where they were—so
many turnings had confused him. But they could not remain there, and so
set off walking towards the forest. In the shelter of the trees, at least, they
would not be so conspicuous if the pursuers again came near. Besides,
Green was certain the saw-mill, which he had once been to, was near trees.

In an hour they found themselves again entering the forest, and walking
along a broad track made by deer or other large animals. It was dark below
the great pine trees, and before long the shades of evening made it still
darker.

"Oh, Green, I can walk no further!" said Cyril at length, sinking down at
the foot of a tree.

"Well, I think we're both about tired out," rejoined Green, leaning
wearily against another tree, and looking down compassionately on the tired
boy. "We'll stop here, lad, for the night."

"Yes. But shall we be safe? What about the wild animals?"

"Oh, we must have a fire! There's plenty of dry wood about."

He went forward and began to heap up some broken boughs.

"It won't do to light it here though," he went on. "We might set fire to the
forest; everything is so burnt up."

"I'm afraid I can't go any further," said Cyril.

"No, you stay there. I'll just take a look round." He walked off as he
spoke, and disappeared amongst the trees.

It was very still after he had gone. The twittering of birds and the
occasional snarl of some wild animal, or the breaking of twigs as one
stealthily approached, were the only sounds to be heard. At another time
Cyril, who was unarmed, might have been nervous had not bodily fatigue
overcome every other sensation. As it was, by the time Green returned to
him he was fast asleep.

"Poor lad, I won't wake him," said the kindly man, lifting Cyril in his
strong arms, and carrying him off as if he were a baby.

When Cyril awoke an hour later he saw a great wood fire burning, and
sending up showers of sparks into the still night air. He was lying in an
open space at one side of the fire, and Green was stooping down near it,
attending to the roasting of a bird.

You might also like