"javascript: the good parts" summary

Post on 29-Nov-2014

5.309 Views

Category:

Technology

1 Downloads

Preview:

Click to see full reader

DESCRIPTION

A summary of Douglas Crockford's amazing book "JavaScript: The Good Parts". First presented at the Baltimore/DC JavaScript Users Group on 7/7/2009. http://www.meetup.com/baltimore-dc-javascript-users/calendar/10560330/

TRANSCRIPT

JavaScript: The Good Parts@jonathanjulian

crockford.com

First, the Bad Parts

globals. optional ;truthy/falsy. scope.

Then, the Good Parts!

functions as objects. loose typing.dynamic objects. literals.

The Bad Parts

globals

• x = 1;

• var y = 1;

• x is in the global namespace

• YourAppName.x = 1;

line termination

• semi-colons are INSERTED by the parser

• optional semi-colons are not a “language feature”

• you are not warned

truthy / falsy

==

===

All of these are false

take advantage

• if (x)

• if (myobject.propery)

• if (myobject.property == null) // no, No, NO!

• test for exactly what you want to test for

• ...or not

• KNOW THE FALSY VALUESundefined, null, false, 0, ‘’, NaN

no block scope

• functions create scope

• blocks do not

The Good Parts!

functions are objects

• can be passed, returned

• have scope

• have closure

loose typing

• no compiler

• no type heirarchies

objects are dynamic

• members can be added to any object, any time

• helpful to attach attributes

object literals

• aka JSON

• { count: 2, prefix: ‘pre_’ }

• pass options to functions

• JSON as communication

• JSON as persistence

• etc

Know the bad parts are there...and avoid them

Learn and love the good parts!

tools

• FireBug

• JSLint

• spidermonkey / rhino / v8

takeaway

• think about vars and scope

• never use ==

• if (myobject) {

• jslint.com

JavaScript is a beautiful language

jonathan.m.julian@gmail.com

@jonathanjulianjonathanjulian.com

top related