Eloquent JavaScript 3rd Edition Marijn Haverbeke - Download The Complete Ebook in PDF Format and Read Freely
Eloquent JavaScript 3rd Edition Marijn Haverbeke - Download The Complete Ebook in PDF Format and Read Freely
https://ebookultra.com/download/eloquent-javascript-a-modern-
introduction-to-programming-1st-edition-marijn-haverbeke/
https://ebookultra.com/download/eloquent-javascript-a-modern-
introduction-to-programming-2nd-edition-marijn-haverbeke/
https://ebookultra.com/download/beginning-javascript-3rd-ed-edition-
paul-wilton/
https://ebookultra.com/download/javascript-a-beginner-s-guide-3rd-ed-
edition-pollock/
JavaScript jQuery The Missing Manual 3rd Edition David
Sawyer Mcfarland
https://ebookultra.com/download/javascript-jquery-the-missing-
manual-3rd-edition-david-sawyer-mcfarland/
https://ebookultra.com/download/professional-javascript-for-web-
developers-3rd-edition-nicholas-c-zakas/
https://ebookultra.com/download/special-edition-using-javascript-
mcfedries/
https://ebookultra.com/download/pro-javascript-with-mootools-learning-
advanced-javascript-programming-1st-edition-mark-joseph-obcena-auth/
https://ebookultra.com/download/javascript-creativity-exploring-the-
modern-capabilities-of-javascript-and-html5-1st-ed-edition-hudson/
Eloquent JavaScript 3rd Edition Marijn Haverbeke
Digital Instant Download
Author(s): Marijn Haverbeke
ISBN(s): 9781593279509, 1593279507
Edition: 3
File Details: PDF, 2.16 MB
Year: 2018
Language: english
Eloquent JavaScript
3rd edition
Marijn Haverbeke
Copyright © 2018 by Marijn Haverbeke
You can buy a print version of this book, with an extra bonus chapter included,
printed by No Starch Press at http://a-fwd.com/com=marijhaver-20&asin-
com=1593279507.
i
Contents
Introduction 1
On programming . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
Why language matters . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
What is JavaScript? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
Code, and what to do with it . . . . . . . . . . . . . . . . . . . . . . . 7
Overview of this book . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
Typographic conventions . . . . . . . . . . . . . . . . . . . . . . . . . . 8
2 Program Structure 22
Expressions and statements . . . . . . . . . . . . . . . . . . . . . . . . 22
Bindings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23
Binding names . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25
The environment . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25
Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26
The console.log function . . . . . . . . . . . . . . . . . . . . . . . . . . 26
Return values . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27
Control flow . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27
Conditional execution . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28
while and do loops . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30
Indenting Code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31
for loops . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32
Breaking Out of a Loop . . . . . . . . . . . . . . . . . . . . . . . . . . 33
ii
Updating bindings succinctly . . . . . . . . . . . . . . . . . . . . . . . 34
Dispatching on a value with switch . . . . . . . . . . . . . . . . . . . . 34
Capitalization . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35
Comments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 36
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37
Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37
3 Functions 39
Defining a function . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 39
Bindings and scopes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 40
Functions as values . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 42
Declaration notation . . . . . . . . . . . . . . . . . . . . . . . . . . . . 43
Arrow functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 44
The call stack . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 45
Optional Arguments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 46
Closure . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 47
Recursion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 49
Growing functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 51
Functions and side effects . . . . . . . . . . . . . . . . . . . . . . . . . 54
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 55
Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 55
iii
Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 79
5 Higher-Order Functions 82
Abstraction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 83
Abstracting repetition . . . . . . . . . . . . . . . . . . . . . . . . . . . 83
Higher-order functions . . . . . . . . . . . . . . . . . . . . . . . . . . . 85
Script data set . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 86
Filtering arrays . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 87
Transforming with map . . . . . . . . . . . . . . . . . . . . . . . . . . . 88
Summarizing with reduce . . . . . . . . . . . . . . . . . . . . . . . . . . 88
Composability . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 90
Strings and character codes . . . . . . . . . . . . . . . . . . . . . . . . 91
Recognizing text . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 93
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 95
Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 95
iv
Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 126
10 Modules 167
Modules . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 167
v
Packages . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 168
Improvised modules . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 169
Evaluating data as code . . . . . . . . . . . . . . . . . . . . . . . . . . 170
CommonJS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 171
ECMAScript modules . . . . . . . . . . . . . . . . . . . . . . . . . . . . 173
Building and bundling . . . . . . . . . . . . . . . . . . . . . . . . . . . 175
Module design . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 176
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 178
Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 178
vi
HTML . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 218
HTML and JavaScript . . . . . . . . . . . . . . . . . . . . . . . . . . . 221
In the sandbox . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 222
Compatibility and the browser wars . . . . . . . . . . . . . . . . . . . 222
vii
16 Project: A Platform Game 261
The game . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 261
The technology . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 262
Levels . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 262
Reading a level . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 263
Actors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 265
Encapsulation as a burden . . . . . . . . . . . . . . . . . . . . . . . . . 268
Drawing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 269
Motion and collision . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 274
Actor updates . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 277
Tracking keys . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 279
Running the game . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 280
Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 282
viii
The form as a whole . . . . . . . . . . . . . . . . . . . . . . . . . . . . 318
Text fields . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 320
Checkboxes and radio buttons . . . . . . . . . . . . . . . . . . . . . . . 321
Select fields . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 322
File fields . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 323
Storing data client-side . . . . . . . . . . . . . . . . . . . . . . . . . . . 325
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 327
Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 328
20 Node.js 350
Background . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 350
The node command . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 351
Modules . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 352
Installing with NPM . . . . . . . . . . . . . . . . . . . . . . . . . . . . 353
The file system module . . . . . . . . . . . . . . . . . . . . . . . . . . . 355
The HTTP module . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 357
Streams . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 359
A file server . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 361
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 366
Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 367
ix
Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 387
x
“We think we are creating the system for our own purposes. We
believe we are making it in our own image... But the computer is
not really like us. It is a projection of a very slim part of ourselves:
that portion devoted to logic, order, rule, and clarity.”
—Ellen Ullman, Close to the Machine: Technophilia and its
Discontents
Introduction
This is a book about instructing computers. Computers are about as common
as screwdrivers today, but they are quite a bit more complex, and making them
do what you want them to do isn’t always easy.
If the task you have for your computer is a common, well-understood one,
such as showing you your email or acting like a calculator, you can open the
appropriate application and get to work. But for unique or open-ended tasks,
there probably is no application.
That is where programming may come in. Programming is the act of con-
structing a program—a set of precise instructions telling a computer what to do.
Because computers are dumb, pedantic beasts, programming is fundamentally
tedious and frustrating.
Fortunately, if you can get over that fact, and maybe even enjoy the rigor
of thinking in terms that dumb machines can deal with, programming can be
rewarding. It allows you to do things in seconds that would take forever by
hand. It is a way to make your computer tool do things that it couldn’t do
before. And it provides a wonderful exercise in abstract thinking.
Most programming is done with programming languages. A programming
language is an artificially constructed language used to instruct computers. It
is interesting that the most effective way we’ve found to communicate with a
computer borrows so heavily from the way we communicate with each other.
Like human languages, computer languages allow words and phrases to be
combined in new ways, making it possible to express ever new concepts.
At one point language-based interfaces, such as the BASIC and DOS prompts
of the 1980s and 1990s, were the main method of interacting with computers.
They have largely been replaced with visual interfaces, which are easier to learn
but offer less freedom. Computer languages are still there, if you know where
to look. One such language, JavaScript, is built into every modern web browser
and is thus available on almost every device.
This book will try to make you familiar enough with this language to do
useful and amusing things with it.
1
On programming
Besides explaining JavaScript, I will introduce the basic principles of program-
ming. Programming, it turns out, is hard. The fundamental rules are simple
and clear, but programs built on top of these rules tend to become complex
enough to introduce their own rules and complexity. You’re building your own
maze, in a way, and you might just get lost in it.
There will be times when reading this book feels terribly frustrating. If you
are new to programming, there will be a lot of new material to digest. Much of
this material will then be combined in ways that require you to make additional
connections.
It is up to you to make the necessary effort. When you are struggling to follow
the book, do not jump to any conclusions about your own capabilities. You are
fine—you just need to keep at it. Take a break, reread some material, and make
sure you read and understand the example programs and exercises. Learning is
hard work, but everything you learn is yours and will make subsequent learning
easier.
2
art of programming is the skill of controlling complexity. The great program
is subdued—made simple in its complexity.
Some programmers believe that this complexity is best managed by using
only a small set of well-understood techniques in their programs. They have
composed strict rules (“best practices”) prescribing the form programs should
have and carefully stay within their safe little zone.
This is not only boring, it is ineffective. New problems often require new
solutions. The field of programming is young and still developing rapidly, and
it is varied enough to have room for wildly different approaches. There are
many terrible mistakes to make in program design, and you should go ahead
and make them so that you understand them. A sense of what a good program
looks like is developed in practice, not learned from a list of rules.
That is a program to add the numbers from 1 to 10 together and print out
the result: 1 + 2 + ... + 10 = 55. It could run on a simple, hypothetical
machine. To program early computers, it was necessary to set large arrays of
switches in the right position or punch holes in strips of cardboard and feed
them to the computer. You can probably imagine how tedious and error-prone
this procedure was. Even writing simple programs required much cleverness
and discipline. Complex ones were nearly inconceivable.
Of course, manually entering these arcane patterns of bits (the ones and
zeros) did give the programmer a profound sense of being a mighty wizard.
And that has to be worth something in terms of job satisfaction.
Each line of the previous program contains a single instruction. It could be
written in English like this:
3
1. Store the number 0 in memory location 0.
2. Store the number 1 in memory location 1.
3. Store the value of memory location 1 in memory location 2.
4. Subtract the number 11 from the value in memory location 2.
5. If the value in memory location 2 is the number 0, continue with instruc-
tion 9.
6. Add the value of memory location 1 to memory location 0.
7. Add the number 1 to the value of memory location 1.
8. Continue with instruction 3.
9. Output the value of memory location 0.
Although that is already more readable than the soup of bits, it is still rather
obscure. Using names instead of numbers for the instructions and memory
locations helps.
Set “total” to 0.
Set “count” to 1.
[loop]
Set “compare” to “count”.
Subtract 11 from “compare”.
If “compare” is zero, continue at [end].
Add “count” to “total”.
Add 1 to “count”.
Continue at [loop].
[end]
Output “total”.
Can you see how the program works at this point? The first two lines give
two memory locations their starting values: total will be used to build up the
result of the computation, and count will keep track of the number that we are
currently looking at. The lines using compare are probably the weirdest ones.
The program wants to see whether count is equal to 11 to decide whether it
can stop running. Because our hypothetical machine is rather primitive, it can
only test whether a number is zero and make a decision based on that. So it
uses the memory location labeled compare to compute the value of count - 11
and makes a decision based on that value. The next two lines add the value
4
of count to the result and increment count by 1 every time the program has
decided that count is not 11 yet.
Here is the same program in JavaScript:
let total = 0, count = 1;
while (count <= 10) {
total += count;
count += 1;
}
console.log(total);
// → 55
The moral of this story is that the same program can be expressed in both
long and short, unreadable and readable ways. The first version of the program
was extremely obscure, whereas this last one is almost English: log the sum of
the range of numbers from 1 to 10. (We will see in later chapters how to define
operations like sum and range.)
A good programming language helps the programmer by allowing them to
talk about the actions that the computer has to perform on a higher level.
It helps omit details, provides convenient building blocks (such as while and
console.log), allows you to define your own building blocks (such as sum and
range), and makes those blocks easy to compose.
5
What is JavaScript?
JavaScript was introduced in 1995 as a way to add programs to web pages in the
Netscape Navigator browser. The language has since been adopted by all other
major graphical web browsers. It has made modern web applications possible—
applications with which you can interact directly without doing a page reload
for every action. JavaScript is also used in more traditional websites to provide
various forms of interactivity and cleverness.
It is important to note that JavaScript has almost nothing to do with the
programming language named Java. The similar name was inspired by mar-
keting considerations rather than good judgment. When JavaScript was being
introduced, the Java language was being heavily marketed and was gaining
popularity. Someone thought it was a good idea to try to ride along on this
success. Now we are stuck with the name.
After its adoption outside of Netscape, a standard document was written
to describe the way the JavaScript language should work so that the various
pieces of software that claimed to support JavaScript were actually talking
about the same language. This is called the ECMAScript standard, after the
Ecma International organization that did the standardization. In practice, the
terms ECMAScript and JavaScript can be used interchangeably—they are two
names for the same language.
There are those who will say terrible things about JavaScript. Many of these
things are true. When I was required to write something in JavaScript for the
first time, I quickly came to despise it. It would accept almost anything I typed
but interpret it in a way that was completely different from what I meant. This
had a lot to do with the fact that I did not have a clue what I was doing, of
course, but there is a real issue here: JavaScript is ridiculously liberal in what
it allows. The idea behind this design was that it would make programming in
JavaScript easier for beginners. In actuality, it mostly makes finding problems
in your programs harder because the system will not point them out to you.
This flexibility also has its advantages, though. It leaves space for a lot of
techniques that are impossible in more rigid languages, and as you will see
(for example in Chapter 10), it can be used to overcome some of JavaScript’s
shortcomings. After learning the language properly and working with it for a
while, I have learned to actually like JavaScript.
There have been several versions of JavaScript. ECMAScript version 3 was
the widely supported version in the time of JavaScript’s ascent to dominance,
roughly between 2000 and 2010. During this time, work was underway on
an ambitious version 4, which planned a number of radical improvements and
extensions to the language. Changing a living, widely used language in such a
6
radical way turned out to be politically difficult, and work on the version 4 was
abandoned in 2008, leading to a much less ambitious version 5, which made
only some uncontroversial improvements, coming out in 2009. Then in 2015
version 6 came out, a major update that included some of the ideas planned
for version 4. Since then we’ve had new, small updates every year.
The fact that the language is evolving means that browsers have to constantly
keep up, and if you’re using an older browser, it may not support every feature.
The language designers are careful to not make any changes that could break
existing programs, so new browsers can still run old programs. In this book,
I’m using the 2017 version of JavaScript.
Web browsers are not the only platforms on which JavaScript is used. Some
databases, such as MongoDB and CouchDB, use JavaScript as their scripting
and query language. Several platforms for desktop and server programming,
most notably the Node.js project (the subject of Chapter 20), provide an envi-
ronment for programming JavaScript outside of the browser.
7
only there. In addition, many chapters define bigger programs, and the pieces
of code that appear in them depend on each other or on external files. The
sandbox on the website provides links to Zip files containing all the scripts and
data files necessary to run the code for a given chapter.
Typographic conventions
In this book, text written in a monospaced font will represent elements of
programs—sometimes they are self-sufficient fragments, and sometimes they
just refer to part of a nearby program. Programs (of which you have already
seen a few) are written as follows:
8
Other documents randomly have
different content
and the remainder is Úbygð (hod. Obygð) or desert—a chaos of sand-tracts and peat-swamps, lava-runs,
and the huge masses of eternal congelation called Jökulls.[154]
The population was laid down by Barrow (1834) at 0·2 per whole area, and by Paijkull (1865) at
1·6: being now assumed at 70,000, it would be 1·75. Paijkull makes 6·2 head the average of habitable
ground, and for the reclaimed tracts he gives 17·5. The latter figure exceeds the mean of Africa, which is
16 to the square mile (viz, 192,000,000 head to 11,556,000 square statute miles), and it is three times
greater than in the whole Western Hemisphere.
§ 2. Divisions.
In early Norwegian days (A.D. 965) Iceland was distributed, like Ireland, into four quadrants, tetrads,
or fourths (Fjórðungar), named after the points of the compass. These were—
Before A.D. 1770. one Amtmaðr governed the whole of Iceland; in that year it was divided into two
Amts (rules), the north-eastern and the south-western. Thus the northern and the eastern quadrants,
whose population was scanty, were placed for administrative purposes under a single Amt, the
headquarters being at Fríðriksgáfa, of old Möðruvellir, near Akureyri, on the western shore of the
Eyjafjörð. In 1787 the south-west Amt was divided into two, the southern and the western. In 1872 it
was proposed to unite the western with the southern tetrarchy, and to transfer the amtship of
Stykkishólm to Reykjavik, the capital. Thus there will again be only two Amts under the governor, and
this simplification may act well.
The official title of the highest official was Stiptamtmaðr; in Danish, Stiftamtmand.[155] It has lately
been changed, without, however, any other advantage of rank or pay, from High Bailiff to Governor-
General (Landshöfðingi). Formerly the military and naval services had a preference, and titled names
were not rare: at present the post is given to civilians.[156] The salary of this high official was $500 in
1772; it afterwards became $2000, and now it is $4000.
The four quarters were divided into Sýslur[157] (Dan. Syssel), which are ever changing. For
instance, the Gullbróngu and Kjósar have lately been united, politically as well as ecclesiastically; the
same has happened to Mýra Sýsla and Hnappadals, whilst the vacancies have been filled up by the
Vestmannaeyjar. Under the twenty-one Sýslur, cantons or counties, prefectures or sheriffdoms, are the
169 Hrepps or poor-law districts,[158] which are not like our ecclesiastic divisions. We have preserved in
England the word,e.g., Rape of Brambor.
The following is a list of Sýslur and Hreppar, taken from the official documents which show the
movement of Iceland in 1868.[159]
The Suður-umdæmið, or southern jurisdiction, contains 7 Sýslur and 48 Hreppar, viz.:
When the author visited Iceland (1872), the Bæarfógeti, or mayor of Reykjavik, was Amtmaðr for
the southern quarter. Hr Christián Christiánsson ruled the north and east at Fríðriksgáfa, and Hr Bergur
Thorberg, knight of the Dannebrog, had his headquarters at Stykkishólm on the western fourth. Now
(1874), Hr Bergur Thorberg governs the southern and western quadrants, and Hr Christían
Christiánsson, with the title of Justitsráð, the northern and the eastern. These officers are addressed as
Hávelborni, and they receive the reports of the several Sýslumenn.
The Sýlumenn, or sheriffs, are the civil staff, the tax-gatherers and stewards as it were of the king;
and appointed by the Crown. In order to obtain this office they must be graduates of the University of
Copenhagen; they wear uniforms, a gold band round the cap, frock coats, waistcoats, and vests of blue
broadcloth, with the royal button, and they may become ministers of state. They preside at the
Hèraðthings[161] or annual county courts; they watch over the peace of their shrievalties; they officiate
as public notaries; and they maintain the rights of inheritance. The Sýslumaðr in his judicial capacity,
and chiefly when land-questions are to be determined, is occasionally assisted by four Meðdómsmenn
(concessores judicii), who give suffrage and register proceedings; decisions are pronounced according to
the vote of the majority.[162] He superintends elections. Formerly he could compel the lieges to repair
the highways, and the law still obliges each landed proprietor to keep the rough fences upon his estate in
good condition. A small sum called Vegabótargjald is also taken by the Sýslumaðr to pay for the
necessary expenses of roads; unfortunately the corvée or robot of peasants has been abolished, and the
means of transit are much neglected. A law compelling all sturdy vagrants and able-bodied paupers to
work upon the highways is as much wanted in Iceland, as useful and productive employment for the
hordes of soldiers who now compose the standing armies of Europe.
Under the Sýslumenn and appointed by the Amtmenn are the Hreppstjórar or Hreppstjórnarmenn,
bailiffs and poor-inspectors with parochial jurisdiction. It is hardly to be doubted that the division into
Rapes existed in heathen days, and Dr Konrad Maurer believes that they had organised poor laws and
rules for vagrancy which the Christian bishops afterwards amended and expanded. In these days the
Rape-stewards assist their civil and ecclesiastical superiors to manage the business of the Rape, to
preserve public order, and to estimate cessable property according to the ancient custom of the island.
They fix the poor-rate for each land-holder, and they especially attend to the condition and maintenance
of paupers (Úmagar), who are no longer subject to the pains and penalties of that ancient code the
Grágás (grey or wild goose).[163] Where the parish exceeds 400 souls, these minor officials usually
number two to five. They are substantial yeomen who wear no distinctive dress. They and their children
are exempt from taxation, and this is their only salary. The functions of the Amtmenn, Sýslumenn, and
of the Hreppstjórar especially, will be greatly modified when the law of May 4th, 1872, comes into
operation during the present year. A standing Hreppsnefnd, or a committee of three, five, or seven, is to
be elected in each Hreppr. This body is to have charge of the poor, the sanitary conditions, and the
general business of the Hreppr, including the repair of roads. It is also to levy the poor-rates and other
cesses of the Hreppr. The Hreppstjórar will be retained, but their functions are not defined. A Sýslunefnd
is also to be elected in each Sýsla, consisting of six to ten members; and the Sýslumaðr is ex officio a
convener or foreman of this committee. It is to have charge of the roads, to manage the general business
of the Sýsla, and to exercise supervision over the Hreppsnefndir. Thirdly, Amtsrað, Amt-Councils,
consisting of the Amtmaðr and two elected members, will audit and control all the accounts of the Amt;
will act as trustees of all public institutions and public legacies, and will have supervision over the
Hreppsnefndir and Sýslunefndir.
§ 3. Judicial Procedure.
It is well known that trial by jury, the bulwark of Englishmen’s rights, though fathered by English
legal antiquaries upon King Alfred, is a purely Scandinavian institution. According to the Landnámabók
(II., ix., note, p. 83), the Kviðr plays a considerable part in the republican history; and the form of trial
like our juries de vicineto appears in the thirteenth century. As Mr Vigfússon remarks (Cleasby, sub voce
Kviðr): “From the analogy of the Icelandic customs, it can be inferred with certainty that, along with the
invasion of Danes and Norsemen, the judgment by verdict was also transplanted to English ground, for
the settlers of England were kith and kin to those of Iceland, carrying with them the same laws and
customs; lastly, after the Conquest, it became the law of the land. This old Scandinavian institution
gradually died out in the mother countries[164] and ended in Iceland, A.D. 1271-1281, with the fall of the
Commonwealth and the introduction of a Norse code of laws, whereas it was naturalised in England,
which came to be the classical land of trial by jury.”
Modern Iceland utterly ignores it, but, as in the United States, all freemen are familiar with judicial
procedures, and public opinion, not to speak of the press, is a sufficient safeguard for a small
community.
In criminal cases the Crown prosecutes, and the king must ratify capital sentences. Like the Cives of
Rome, and very unlike the subjects of civilised Europe, Icelanders are not confined before trial, there
being no houses of detention; but a criminal is kept either by the sheriff or the hreppstjóri, who is
responsible for his being brought to judgment at an order from the court. By way of checking the
litigiousness of the lieges, a regular system of arbitration is in force. The parish priest ex officio and one
of his parishioners are the Forlíkunarmenn (reconciliators), and act as umpires; and a previous
investigation of causes often quashes them.
It is only in administrative cases, e.g., about paupers, etc., that there is an appeal from the decisions
of the sheriff to the Amtmaðr. From the Sýslumaðr’s court civil causes go for cassation directly to the
Supreme Court (Konunglegi-Landsyfirrettur) of Reykjavik, which was instituted in A.D. 1800, when the
Althing, which then had judicial as well as legislative and administrative functions, was abolished. The
Royal Court consists of a Chief Justice (Justiciarius) and two assessors; the governor presides, but takes
no part in the judicial proceedings. All three votes are equal, and the majority decides, thus making the
judge and assessors jury as well as judges. The actual dignitaries are Hr Thórður Jonasson, Hr Jón
Pétursen, and Hr Magnús Stephensen; the salaries are, $2816, $2016, and $1416. There are also two
procurators (the English barrister and the Scotch advocate), Hr Páll Melsted and Hr Jón Guðmundsson,
who edits the leading newspaper. Hr P. Guðjónsson, the church organist, is not a procurator although he
occasionally conducts cases before the superior court.
At this Royal High Court of Judgment the evidence and pleadings of both parties are heard, and the
Justiciarius, after taking the opinions of his assessors, pronounces his decision. For cassation, causes
must then go to the Chancellerie, or Supreme Court of Judicature at Copenhagen.
SECTION V.
ANTHROPOLOGY.
§ 1. Statistics.
The constitution of society and the physical features of Iceland are peculiarly favourable to
numbering the people. The island has no object either to diminish her total in order to avoid recruiting,
and has scant interest in exaggerating it with a view to urban concessions and civic privileges. Between
A.D. 1840-60 the census was quinquennial; since that time every decade has been deemed sufficient.
The following numbers are taken from various sources, and especially from the latest official
figures in the Skýrslur of October 1, 1870:
In A.D. 1770 Uno Von Troil (p. 25) estimated the population at 60,000 souls, or about 10,000 more
than sixty years after the Norwegian colonisation. In 1783 the total fell to 47,287, and in 1786 to 38,142
(Preyer and Zirkel, p. 483). Since the beginning of the present century we have exact and minute
computations:
Statistisk Tabel-Værk.
S. Qr. W. Qr. N. & B. Qrs. Total.
In A.D. 1801, 17,160 13,976 16,104 46,240(47,207?)
” 1806 (Preyer and Zirkel, whereas Mackenzie assigns it to 1804), 46,349
” 1808 (Preyer and Zirkel; and Mackenzie, p. 280), 48,063
” 1834, (Dillon, unofficial, evidently “round numbers”) 53,000
” 1835, 20,292 14,480 21,263 56,035
” 1840, 20,677 14,665 21,752 57,094
” 1842 (Meddel., ii. 70), 53,000
” 1845, 21,364 14,956 22,238 58,358
Skýrslur.
S. Qr. W. Qr. N. & E. Qrs. Total.
In A.D. 1850, 21,288 15,112 22,757 59,157
” 1855, 22,810 16,362 25,431 64,603
” 1857 (Preyer and Zirkel), 66,929
” 1858 (Do.), 67,847
” 1860, 23,137 16,960 26,890 66,987
” 1865 (Vice-Consul Crowe), 68,000
” 1870, 25,063 17,001 27,699 69,763
” 1872 (estimated), 70,000
while that of Madeira is 80,000.
The following table (Skýrslur um landshagi á Íslandi, v. 310, 1872) shows the increase of
population during the present century down to 1870:
The average rate of increase during the last century was very small: between A.D. 1703 and 1758 it
was about one-fifth of 1 per cent. During the present age there has been, we observe, a tolerably regular
progress with only three exceptions (A.D. 1835-40, A.D. 1845-50, and A.D. 1860-70). During this decade
(1860-70) there has been a considerable failure, 4·14 per cent., or only 2·05 for each lustrum. In 1872,
as will be seen, the number of males was 33,102; of females, 36,660. But throughout Iceland the
fluctuations have ever been so great as to reduce the value of “general considerations.”
The following tables are compiled from the minute returns made to the Danish Government, and
published in vols. i.-vi· of 1852-61, of the Meddelser fra det Statistishe Bureau, Copenhagen.
No. 1.—Table showing the Population of Iceland and its Distribution on the 1st February 1850, and
on the 1st October 1855.
Western Amt.
Mýra and Hnappadals Sýsla,{*} 379 383 2410 2569 6·60
Snæfellsness Sýsla, 512 526 2684 2825 5·25
Dala Sýsla, 267 277 1923 2104 9·41
Barðastrandar Sýsla, 336 347 2518 2703 7·35
Isafjarðar{***} Sýsla, 508 545 4204 4589 9·16
Stranda Sýsla, 179 190 1373 1572 14·49
Total (Western Amt), 2181 2268 15,112 16,362 8·27
No. III.—Table showing the Means of Support of the Population of Iceland on the 1st October 1855.
PROVIDING SUPPORTED. Percentage
TOTAL.
OCCUPATIONS. SUPPORT. Wives & Families. Servants. of
Males. Females. Total. Males. Females. Total. Males. Females. Total. Males. Females. Population. Total.
Ecclesiastics and
196 7 203 399 623 1022 527 613 1140 1122 1243 2365 3·66
teachers,
Civil officials
45 2 47 74 105 179 105 123 228 224 230 454 0·70
and employés,
Persons who live
84 89 170 40 84 124 18 44 62 139 217 356 0·55
on their means,
Men of science
29 — 29 20 42 62 20 29 49 69 71 140 0·22
and letters,
Persons who live
7063 618 7681 11,835 19,354 31,189 6112 7493 13,605 25,010 27,465 52,475 81·23
by agriculture,
Persons who live
980 86 1066 1090 1925 3015 465 509 974 2535 2520 5055 7·82
by the sea,
Mechanics, 199 27 226 133 219 352 59 73 132 391 319 710 1·10
Traders and inn-
87 4 91 136 231 367 117 155 272 340 390 730 1·13
keepers,
Persons who
172 62 234 97 168 265 13 11 24 282 241 523 0·81
work by the day,
Others who
pursue no
162 123 285 67 172 239 20 42 62 249 337 586 0·91
definite
occupation,
Receiving alms, 497 710 1207 — — — — — — 497 710 1207 1·87
Prisoners, 2 — 2 — — — — — — 2 — 2 0·00
Total, 9513 1728 11,241 13,891 22,923 36,814 7456 9092 16,548 30,860 33,743 64,603 100·00
Percentage of
14·7 2·7 17·4 21·5 35·5 57·0 11·5 14·1 25·6 47·8 52·2 100·0 —
population,
Southern Amt.
Reykjavik, 356 1444 2024
Gullbríngu and Kjósar Sýsla, 824 5001 5302 + 13·7
Borgarfjarðar Sýsla, 352 2251 2590 + 15·1
Árnes Sýsla, 772 5409 5891 + 8·9
Rángárvalla Sýsla, 689 5034 5201 + 3·3
Austr and Vestr Skaptafells Sýsla, 490 3499 3484 - 0·4
Vestmannaeyja Sýsla, 885 499 571 + 14·4
Total (Southern Amt), 3568 23,137 25,063 + 8·3
Western Amt.
Mýra and Hnappadals Sýsla, 373 2663 2765 + 3·9
Snæfellsness Sýsla, 471 2869 2799 - 2·4
Dala Sýsla, 285 2223 2190 - 1·5
Barðastrandar Sýsla, 311 2727 2699 - 1·0
Ísafjarðar Sýsla, 518 4860 4895 + 0·7
Stranda Sýsla, 192 1618 1653 + 2·2
Total (Western Amt), 2150 16,960 17,001 + 0·2
In the Suðr-umdæmið (South Quarter) are 3568 households, with 11,835 men and 13,228 women.
” Vestr ” (West ” ) ” 2150 ” 7,981 ” ” 9,019 “
” Norðr og Austr ” 3588 ” 13,286 ” ” 14,413 “
Total, 9306 33,102 men and 36,660 women.
According to Mr Vice-Consul Crowe (Report), during the average of ten years (1855-65) there was
annually—
In 1855 there were 202 blind and 65 born surd-mutes. In 1870 the former numbered 225 (160 men
and 65 women), and the latter 50 (20 + 30).
In table III. (1855), we see that of 64,603 souls, 52,475, about three-fourths of the heads of families
and those who provide support, lived by farming, that is, by cattle-breeding, whilst more than four-fifths
of the entire population thus derived their maintenance. At the same time, 5055 were fishermen, and
only 703 were traders, showing a primitive state of society. Mr Consul Crowe (Report, 1870-71)
remarks: “Somewhat more than the 75 per cent. of the total population were engaged in sheep rearing
and agricultural pursuits; and, notwithstanding the steady and lucrative nature of the fisheries, only
about 10 per cent. were engaged in them.” The mechanics may be further distributed as follows:
Bakers, (in 1855) 1 proportion per thousand 0·01 in 1870 numbered 2
Coopers, ” 35 ” 0·55 ” 17
Gold & Silver Smiths, ” 80 ” 1·24 ” 21
Blacksmiths, ” 80 ” 1·24 ” 31
Carpenters, ” 61 ” 0·94 ” 12
Masons, ” 6 ” 0·09 ” 2
Millers, ” 4 ” 0·07 ” 1
Turners, ” 8 ” 0·13 ” 1
Boatbuilders, ” 38 ” 0·59 ” 12
Tailors, ” 27 ” 0·41 ” 10
Joiners, ” 174 ” 2·69 ” 56
Saddlers, ” 46 ” 0·71 ” 15
Weavers, ” 20 ” 0·30 ” 4
Watchmakers, ” 0 ” 0·00 ” 1
Other industries, ” 103 ” 1·59 ” 24
According to Mr Consul Crowe (Report, 1870-71), the proportion between births and deaths was:
The tables of 1855 gave an excess of 2865 women. Mackenzie (1801) shows 21,476 males to
25,731 females, or 4255 out of a total of 47,207. In 1865 the proportion of men to women was 1000:
1093. In 1870 the conditions had improved, the surplus being only 3554 out of 69,763, a small
percentage of waste labour.
It is easy to account for the preponderance of women, as well as their superior longevity, without
entering into the knotty subject of what determines sex. They lead more regular lives, they have less
hardship and fatigue, and they are rarely exposed to such accidents as being lost at sea or “in the mist.”
According to Mr Vice-Consul Crowe, in 1865-66, of every forty-two deaths one was by drowning.
There is a tradition that Iceland during its palmiest days contained 100,000 souls, but it seems to rest
upon no foundation. On the other hand, the old superstitious belief that some fatal epidemic invariably
follows an increase beyond 60,000, has, during the last few years, shown itself to be equally groundless.
It is probably one of the post hoc, ergo propter hoc confusions so popular amongst the vulgar; and,
unhappily, not confined to the vulgar.
§ 2. General Considerations.
“The first inhabitants of the northern world, Dania, Nerigos, and Suæcia,” says Saxo Grammaticus,
repeated by Arngrímr Jónsson, “were the posterity and remnant of the Canaanites quos fugavit Jesus
latro—expulsed from Palestine about A.C. 1500 by Joshua and Caleb.” Duly appreciating the
ethnological value of this tradition, we may remark that the occupation of Ultima Thule, which the
ancients evidently held to be inhabited—tibi serviat must mean that there were men to serve—has not
yet been proved. But Mongoloid or præ-Aryan colonies in ancient days seem to have overrun all the
Old, if not the New World, and we must not despair of tracing them to Iceland.
The modern Icelander is a quasi-Norwegian, justly proud of the old home. His race is completely
free from any taint of Skrælling, Innuit,[166] or Mongoloid blood, as some travellers have represented,
and as the vulgar of Europe seem to believe. Here and there, but rarely, a dark flat face, oblique eyes,
and long black horsehair, show that a wife has been taken from the land
“Where the short-legged Esquimaux
Waddle in the ice and snow.”
§3. Character.
and although she has improved upon the reckless licentiousness of the Saga
days, ichthyophagy and idleness must do much to counterbalance the “sun-
clad power of chastity.” The “unsophistication” of the race is certainly on
the wane; there are doubtless
§ 3. Society.
Abroad, his emulation is excited, his ambition is roused, and his slow
sturdy nature is stirred up to unusual energy. At home he can command no
serious education, nor can he escape from the indolent and phlegmatic, the
dawdling and absolutely unconditioned slowness of the country, where time
is a positive nuisance, to be killed as it best can. In Iceland the author met
several Danes, but only two Icelanders, who spoke good English, French, or
German; it is far otherwise in Europe, and especially, we need not say, in
England.
As the notices of emigration will show, Iceland, like Ireland, is
instinctively seeking her blessing and salvation, the “racial baptism.” One
traveller records the “inexpressible attachment of the islanders for their
native country.” Their Sehn sucht in a mountainless land, and the time-
honoured boast, “Hið besta land solin skínr uppá” (Iceland is the best land
upon which the sun shines).[178] So Bjarni Thorarensen sings, “World-old
Iceland, beloved foster-land, thou wilt be dear to thy sons, as long as sea
girds earth, men love women, and sun shines on hills.” But all the people of
all the poorest countries console themselves in the same way, and
geographical ignorance confirms an idea which to the traveller becomes
simply ludicrous: moreover, northerners, it need hardly be said, gain more
by removal, and therefore emigrate more readily than southerners. The
latter express themselves unmistakably:
Our website is not just a platform for buying books, but a bridge
connecting readers to the timeless values of culture and wisdom. With
an elegant, user-friendly interface and an intelligent search system,
we are committed to providing a quick and convenient shopping
experience. Additionally, our special promotions and home delivery
services ensure that you save time and fully enjoy the joy of reading.
ebookultra.com