JavaScript: The Good Parts

Why you should read the book

by Bill Sorensen / @BillSorensen
Created with reveal.js

About me

Software developer at Geonetric

Use JavaScript; not an expert

Once met Douglas Crockford in a hallway

About Douglas Crockford

Author of JavaScript: The Good Parts

Specified JSON data format

Developed JSLint

Photo by Franco Folini / CC BY-SA 2.0 / resized

The book

JavaScript: The Good Parts — 172 pages

JavaScript: The Definitive Guide — 1096 pages

Photo by Bill Sorensen

Bad parts

“Most programming languages contain
good parts and bad parts.”

- Douglas Crockford

==

Demo

Always use ===.

switch fall through

Clear as mud?

Always use break.

Block-less statements

Demo

Always use curly braces.

new

Demo

JSLint

Avoiding the bad parts

Warning: It will hurt your feelings.

Let's try it!

Awful parts

Global variables


var foo1 = 1;

function bar() {
    window.foo2 = 2;

    foo3 = 3;
}

bar();
					

No block scope

Demo

Automatic semicolon insertion

Demo

typeof

Demo

Object

Demo

Good parts

Functional language

Functions are first-class objects.

Supports closures - link to outer scope.

Supports anonymous functions.

Demo: lodash

Object/array literals


var person = {
    name: "Bill",
    number: 4
};

var cats = ['Chubbs', 'Addy', 'Dave'];
					

The future

...or the present?

ECMAScript 6 (ES6)

Some of the good:

  • Proper tail call recursion
  • Modules (avoid globals)
  • let is the new var (block scope)
  • Destructuring (similar to F#)
    let { that, other } = some_object;
  • Arrow functions (lambda syntax)

... and bad:

New class syntax

Good parts reconsidered

(Crockford in 2014)

He stopped using:

  • new
  • Object.create()
  • this

References

These slides: http://www.truewill.net/jsgoodparts/
(press S key for presenter notes)

“Don’t make bugs.”

- Douglas Crockford