
Show HN: The JavaScript Way, a book for learning modern JavaScript from scratch - bpesquet
https://github.com/bpesquet/thejsway/#
======
bpesquet
Hi all, author here.

Backstory: I'm a CS engineer/teacher and this book is a side project started
in December 2016. You can read a bit more about it here:
[https://medium.com/@bpesquet/walk-this-javascript-
way-e9c45a...](https://medium.com/@bpesquet/walk-this-javascript-
way-e9c45ab5b696).

The writing process is now completed and I'm actively looking for feedback to
make the book better. Any opinion or advice about content, pricing, or that
hastily created Leanpub cover would be greatly appreciated. However, please
keep in mind that this is a self-published effort still far from being
polished and open to improvement.

I'd also like this thread to stay focused on the book itself, not on the
merits/weaknesses of JavaScript or the usefulness of choosing it as a first
programming language.

Thanks in advance!

~~~
specialist
Nice. Thanks for sharing.

Bravo for burrito recipe. I'm convinced I became a programmer in 4th grade.
Our creative writing assignment was instructions for making a peanut butter &
jelly sandwich. Then our teacher followed our instructions literally. Hilarity
ensued.

\---

I think the Intro's link to the local env setup in the appendix is broken.

Anymore, I always check the colophon first, then decide to proceed.

I applaud the online option.

I'm dubious of the local option. "Install the latest XYZ" will bite you (your
students). Especially with JavaScript and nodejs. Mayflies live longer.

For future, should tutorials start with Docker images, or scripts, or
virtualbox images, or something, to mitigate digital drift? Hoping other
commenters will share their ideas, experiences.

~~~
Cthulhu_
Re: nodeJS versions, I'd go with something like "Install NodeJS, this book was
written with version x.y.z"; I don't think JS will become backwards
incompatible in the near future, so as long as the book doesn't contain
experimental or unofficial JS features, it should be fine for the next 5-10
years.

~~~
rapind
Anecdotal I suppose, but I have an app that was written for node 5 and it
doesn't work on 6+. I'm sure I could figure out and upgrade it, but it's not
too high on the priorities yet thanks to nvm. Oh, and it's not the code, it's
one or more of the npm modules.

~~~
pitaj
Odds are that it is a native module. That's unfortunate, but there is a plan
in place to make a consistent native module API:
[https://github.com/nodejs/abi-stable-node](https://github.com/nodejs/abi-
stable-node)

------
ryanmarsh
I just got home from teaching JavaScript to a room full of people who've never
written a line of code in their life.

This book is missing something critical that most intros to JavaScript
overlook:

How does the student set up the plumbing and run their code?

It's amazing how much of a hump this is for many trying to get started. It
also amazes me how oblivious most of us programmers are to it.

"Just open Chrome Dev Tools" or "put this in a file and run Node" are really
strange computer tasks to someone who has never typed and executed code.

~~~
cr0sh
> "Just open Chrome Dev Tools" or "put this in a file and run Node" are really
> strange computer tasks to someone who has never typed and executed code.

While not a perfect answer to the issue, I often tend to wonder whether or not
we lost something in the transition from traditional microcomputers (Apple
IIe, Commodore, TRS-80, etc) to the PC era...?

Actually, even in the early PC era, the PC booted to ROM BASIC; this was how
personal microcomputers worked.

That said, in the very early history of personal computing, with machines like
the Altair, IMSAI, and Sol - these machines "out of the box" (so to speak)
didn't drop immediately into a ROM BASIC or "monitor"; they usually had to be
"booted" off of some paper tape or other storage media hosting the boot
process (I wasn't around during that period, but I wonder if that was only a
part - if you then had to "bootstrap" your way up the stack to get to
something useful? I know on the Altair, unless you had it set up in ROM to
boot from, you had to hand-toggle some initial boot code in just to read the
larger boot process from paper tape). All of this process was virtually
identical to how commercial and larger systems were booted.

But the Apple changed this, and made the "personal microcomputer" accessible
to the general public. Now, they could power it on, and get to a prompt of
some sort. It still didn't do much, but it wasn't as arcane. All you had to do
was type some stuff...and...you got something in return: A recipe filing
system, a calendar, a poem, a maze, a game of some sort (Hunt the Wumpus!),
etc.

This continued to be the case for (about) a couple of decades - the first real
crack in this was the introduction of the Macintosh, but most people stuck
with the other systems, with the Mac relegated to the desktop publishing realm
mostly (at which it really excelled). Things started to really change in the
late 1980s and early 90s - mainly because of the introduction of more usable
versions of DOS and (later) Windows. Thus, the PC era was born.

People began to stop being creators (of software) and started to become
consumers instead. Not that this was necessarily a bad thing - there were
still creators of course, but this marked a split; there were now two distinct
camps being formed.

With this, though, began the difficulty in teaching programming - if you
didn't know how to get to the interpreter or compiler, you would have a
difficult time learning.

So here we are today. Fortunately, the answer seems to be coming from the web:
There are more than a few sites out there that let you examine, edit, and run
code all from your browser, for more languages than you might have thought
existed (and new ones are added constantly). It isn't the same as it was (from
when I was a kid), but maybe in a way it is better: Help - whether from others
or from some other resource, is just a few clicks away (no longer do you have
to thumb thru magazines or books trying to formulate an answer)...

~~~
xsmasher
I disagree with the "People began to stop being [creators/hacker]" part - the
existing people didn't change, the market OPENED UP to allow people who were
not hackers and computer experts to be computer users. This is a good thing;
otherwise computers would have remained a niche hobby like ham radio or
woodcarving.

You're right that the average computer owner is not as savvy about the
internals as before, but that's just because the pool of computer owners has
expanded so much, on account of the simpler and consistent and more learnable
interfaces.

~~~
oblio
Agreed. PCs scaled to billions of users. Programming knowledge scales to a
much lower level, I believe there's only millions of programmers or at best
tens of millions.

------
sAbakumoff
I think that the best book ever about JS for everyone, especially for those
starting from scratch is [https://github.com/getify/You-Dont-Know-
JS](https://github.com/getify/You-Dont-Know-JS) you simply don't need anything
else

~~~
beeandapenguin
Completely agree, YDKJS is a great book for learning the language. In my
opinion though, it's not the best book for how to practically use JS in the
real world. It would be a great supplement for those looking to learn more
about language details with the book the OP posted.

~~~
sAbakumoff
You can only learn how to practically use the language by...practicing it in
the real world. No book can teach you that because the real world is too
complex.

~~~
in9
Disagree.. A book could easily show you some basics for project/directory
structure, basic code organization, documentation, simple defaults that can
really make life easier for a noob. With that he can get used to it and
compare code he has to work, or is reading, with what he has already been
taught.

~~~
sAbakumoff
I think it's undeniable that we spend most of our time by debugging and fixing
the existing code structure, bugs, defects and sometimes adding new features.
I highly doubt of existence of a book that can teach how to effectively do
that. It's a luxury and real pleasure if you are asked to create the project
from scratch in a real job.

------
le-mark
Very, very nice. I briefly went over some chapters and I especially admire the
'no framework' approach you've taken. I believe there's a real need for a book
like this, kudos to you for making it happen! What inspired you to create
this?

~~~
bpesquet
Thanks for your nice comment.

I'm currently writing a blog post about this experience. Expect it soon on
[https://medium.com/@bpesquet](https://medium.com/@bpesquet).

------
internalfx
Another great JS book on github...

[https://github.com/getify/You-Dont-Know-JS](https://github.com/getify/You-
Dont-Know-JS)

~~~
samuelthomas
This is a pretty great one, and one of the books I recommend for anyone who is
learning JS.

My favorite book to recommend though is Eloquent JavaScript (also free). Just
a fantastic, readable, intro to programming and JS.

[http://eloquentjavascript.net/](http://eloquentjavascript.net/)

~~~
draker
Eloquent is good if your have prior programming experience. It starts easy but
the 4th chapter goes quickly to a level above what I'd expect a beginner to
understand without some exposure to programming or general CS theory. The
exercises include a recursive list and recursive deep comparison.

------
eksemplar
If you ask me all that you need to know about modern JavaScript is that it
exists mainly to sell online learning material.

But I may be a bitter old man and your resource looks pretty good.

------
dotnetkow
Saw this on Reddit last night, poked around on a few pages. It's great! Love
the movie list example on this page:
[https://github.com/bpesquet/thejsway/blob/master/manuscript/...](https://github.com/bpesquet/thejsway/blob/master/manuscript/chapter10.md).
Going from "for" loops into map/filter/reduce concepts is an excellent way to
teach!

------
ThomPete
This is great!

I am fairly familiar with programming having done both AS, Lingo and PHP I
understand code when I see it. I am however not a programmer but more a
technically oriented product designer and so I don't get to practice as often.

I have been trying to get into javascript and while I understand all the
fundamentals it's still not something that I feel comfortable doing which is a
shame as it's kind of the language of the internet.

Skimming through this books it looks like the perfect way for me to spend my
next two weeks of vacation so thank you so much.

Is there a way to to donate to you?

Having made something as comprehensive as this you need to think about how to
break it up so that you keep users engaged and so that you cam maximise your
revenue. Selling books is mostly a spike and then long slow ramp towards halt
so make sure you keep your content alive.

If I may come with two suggestions.

1\. Make a forum for your readers perhaps in the form of an online reading
group so that you have someone to go through the book with.

2\. Make a step by step email course where you go through the book and have
people turn in assignments perhaps even in forums.

3\. Let people hire you as a private teacher perhaps build up . a network of
private teachers. (Ok that was three suggestions)

These I think would be great ways to monetize.

~~~
bpesquet
Thanks for your nice comment and for these suggestions.

You can support my work by buying the ebook version on Leanpub:
[https://leanpub.com/thejsway](https://leanpub.com/thejsway).

Monetization is not my #1 priority right now, but that might change later ;)

------
partycoder
What all these tutorials omit is the tradeoffs JavaScript and node incur in
order to be simple and friendly.

\- In JavaScript: no type annotations, numbers are floating point numbers,
garbage collected, no multi-threading in the language spec. There are some
ways to workaround these limitations, but they're not a part of the language.

\- The concurrency model of node, based on libuv event loop. This dictates
what node is good for and what is not good for. Short lived tasks = good. Long
lived tasks = bad (service degradation + cascading failures bad)

------
leke
I love the tl;dr section. It's basically what I have do when reading books, in
order to recall the essential information without having to read the entire
chapter again. Well played.

------
jchien17
Should one learn ES2015 before learning ES5? Is there any value or need to
learn ES5 if you're not maintaining an old codebase?

~~~
pspeter3
Not all browsers support ES2015 so knowing ES5 first is helpful.

~~~
EduardoBautista
Except on almost any serious project you should be using a transpiler anyways.

~~~
nawtacawp
transpiler?

~~~
tannhauser23
It converts your ES6 code into Javascript that can run on all browsers. It's
how you can get advanced Javascript features before the browsers fully
implement them. Look up Babel.

------
scottmf
Looks great. I love modern JS, and the faster everyone can move on, the
better!

I didn't see any async/await stuff though, is there a reason for that? I'd
imagine it would make some code much easier to follow.

~~~
_pmf_
> and the faster everyone can move on, the better!

Why? Where does this mindset come from?

~~~
nailer
Direct style is easier to reason about. Control passes onto the next line
consistently, for both async and sync operations.

Do you _really_ prefer callbacks or just use them because they were once
necessary? Are they so good you'd use them for sync operations too?

    
    
       add(a, b, function(sum){
         ....
       })
    

Personally: that seems like a waste of time. I'd rather just do:

    
    
      var sum = a + b;
    

Likewise I'd rather do:

    
    
      var response = await superagent.get('https://...')

------
baalimago
Didn't know "var" was outdated. Good stuff, thanks!

~~~
scottmf
You can technically still use var if you wish, but I'm not sure of any reasons
to do so.

When switching to let/const, bear in mind the difference in scope:

var is function-scoped:

    
    
        (function () {
          var x = 1;
        })();
    
        var x === undefined
    

let/const are block-scoped:

    
    
        if (true) {
          var x = 1;
          let y = 1;
          const z = 1;
        }
        x === 1
        y === undefined
        z === undefined

~~~
z3t4
I find function lexical scope more natural for JavaScript which is very
function orientated, where you pass functions around and use closures a lot. I
also find it a PITA having to declare variables before the block, instead of
where they are first used. Ex:

if(..) { ... huge block of code .. var foo = 1; }

Means I do not have to scroll back and forth to declare and set the variables
at different places.

~~~
rounce
In strict mode JS runtimes will hoist the `var` declaration to the top of the
declared scope anyway. So `foo` would be declared at the start of the
containing function scope, regardless of where you appear to declare them.

~~~
inimino
That is not specific to strict mode, in fact. It will always be hoisted.

~~~
z3t4
What I think he means is that if you "use strict" you will get an error if you
reference a undeclared variable, but due to the hoisting you will not get an
error if you use a _var_ iable before it has been declared - if it's declared
later in the scope. But if you use let, you will get an error! Such errors are
trivial to detect even for beginners though ... Something more nasty is when
you have an undeclared (undefined), maybe misspelled object property, then
neither "use strict" block scope, or even const will help. It's also hard to
find such bugs via static analysis, Typescript nor Eslint will detect it! This
is a feature in JavaScript though, and has nothing to do (but often confused)
with block scope vs function scope, or loose type vs strict types. In other
languages you would need several lines of boilerplate just to do something
like "foo.bar=1", and I think the convenience outweigh the possible hard to
debug errors, and I'm also working on a static analysis tool that will detect
some of those errors.

------
noir_lord
This is incredible.

GF wants to learn to program, she has a strong math/finance background and I
think she'd be good at programming but the web can be a bit overwhelming in
totality.

------
oblib
I went over a few chapters this afternoon and really enjoyed what you've put
together. I'll definitely recommend it to friends who ask me about learning to
code.

------
drngdds
This is really good! And I like the dig at 9gag :)

------
minademian
this looks promising. I like how it teaches the concepts using plain
Javascript without focusing on a tool or library. Kudos.

