Cover photo
Douglas Crockford
Works at PayPal
Lives in San Jose


Douglas Crockford

Discussion  - 
Yesterday I announced a new version of JSLint for ES6. This morning it is top of the search results on Bing. It hasn't shown up on Google yet, which is surprising since I made the announcement here.
Add a comment...

Douglas Crockford

Shared publicly  - 
I was in the games business back in The Atari Age, but I eventually got bored with it and moved on. castAR is giving me the itch again.
Wicked Logic's profile photoChris Jones's profile photoNufayl Razick's profile photoIvan Pierre's profile photo

Douglas Crockford

Shared publicly  - 
RegExp and Template Strings

JavaScript's RegExp constructor takes a string and returns a regular expression object. It is really difficult to use. Regular expressions are difficult to write because the notation is so terse and all mushed together. Writing regular expressions with string literals is even harder because of the need to double the backslashes and escape the quotes. It was recommend that you always use regular expression literals instead.

ES6 introduces a new string literal, the unfortunately named template string. It wraps a string in ` characters, allows it to span several lines, and avoids escapement. This turns out to be really helpful when composing regular expressions.

For example, make a little helper function that wraps RegExp while automatically deleting whitespace.

    function regexp(string, flags) {
        return new RegExp(string.replace(/\s/, ''), flags);

Soon, instead of writing

    var rx_number = /^(0(?:b[01]+|o[0-7]+|x[0-9a-fA-F]+|\.[0-9]+(?:e[+\]?[0-9]+)?)?|[1-9][0-9]*(?:\.[0-9]+)?(?:e[+\]?[0-9]+)?)$/;

ES6 allows you to instead write

    const rx_number = regexp(`^(
        0   (?:
                b [01]+
            |   o [0-7]+
            |   x [0-9 a-f A-F]+
            |   \. [0-9]+ (?: e [+\-]? [0-9]+ )?
    |   [1-9] [0-9]*
            (?: \. [0-9]+ )? (?: e [+\-]? [0-9]+ )?

Which one would you want to maintain?

Regular expressions are still cryptic and bizarre, and I hope that someday we get a notation that is more reasonable, like the Rebol parse dialect. But until then, template strings are a huge improvement.
Christoph Lühr's profile photoАнатолий Демидович's profile photo

Douglas Crockford

Discussion  - 
Should there be a warning on top level loops, that is loops that are not within a function?

Similarly, should there be warnings for top level switches and ifs?

Suggestion: There are a small number of features that make sense at the top level. Using any of the others is likely to be problematic. The top level should allow definition of variables and functions, trys, assignments, invocations, and ifs around the assignments and invocations. Everything else presents warnings, including loops, switches, etc.
Daniel Langdon's profile photoKristian Høy Horsberg's profile photoFelix E. Klee's profile photoAntony Scriven's profile photo
Actually, I retract what I said earlier: I don't think that JSLint should set any options for Node.js, since module-level source code isn't really ES5-compliant.
Add a comment...

Douglas Crockford

Shared publicly  - 
I will be speaking in San Francisco on Tuesday evening at Bigcommerce. See you there.
Want to learn how to use programming languages more effectively?    Want a review of the new good parts in ES6? Or do you just want an autograph from the creator of JSON? Come join us for a tech talk by Douglas Crockford on  "The Better Parts!" About the Talk: This talk is about using programming languages more effectively, and using that experience to create and select better programming languages. There are bad practices in software develo...
Mark Bridge's profile photoLevente Varga's profile photo


Douglas Crockford

Discussion  - 

I am doing the first rewrite of JSLint since the project began in 2001. It is not finished yet, but it is stable enough that you can start poking at it. I have significantly changed the way options work. There are far fewer of them, and they work at file granularity, not block as before. I have moved this and for to the endangered list as we are now able to better embrace the functional paradigm. I haven't figured out what to do with arguments yet.

This rewrite was motivated by ES6. The old version was designed for ES3. New features like megastring literals and farts are a challenge to the old framework.

I expect the new version is way too strict in some ways, and way too lenient in others. It will take some time to get the balance right.

The things I am looking for right now are crashes: texts that JSLint is unable to complete.
JSLint, The JavaScript Code Quality Tool. This file allows JSLint to be run from a web browser. It can accept a source program and analyze it without sending it over the network.
PhistucK Productions's profile photoNorbert Fuhs's profile photoAlex Lambiris's profile photoSamokhin Alex's profile photo
Bug -
Expected 'use strict' and instead saw 'var'. line 1 column 5
     var bar =, baz;
Unexpected ','. line 1 column 22
     var bar =, baz;
Undeclared 'baz'. line 1 column 24
     var bar =, baz;
Undeclared 'baz'. line 2 column 18
     return bar + baz;

Code -
function fooBar(foo) {
     var bar =, baz;
     return bar + baz;
Add a comment...

Douglas Crockford

Shared publicly  - 
CSS Question:

I want to underline all of a span except the first letter. I put a decoration on the span, and put a decoration of none on the ::first-letter. But that doesn't work because none does not remove the underline, it only doesn't add any additional decoration.

I can do this trivially with <u>:


Is there a way to do it with CSS?
Sam Anderson's profile photoAubrey Taylor's profile photoPanos Papadopoulos's profile photoIshmael Ahmed's profile photo
That is the problem I identified at the very beginning of this topic. I was looking for confirmation of my reading that CSS in its current form is broken. I was hoping that I was missing something, but it seems now that I wasn't. Thank you.

Douglas Crockford

Shared publicly  - 
There are two letters that have been allowed in number literals, E and X. Should they be written in upper case or lower case? There doesn't seem to be any good argument to support either case.

ES6 gives us an answer. ES6 introduces two new letters, B and O, which are used to indicate binary and octal, respectively. O is obviously a terrible choice because it looks like zero. This badness is mitigated by using the lower case o.

So in number literals, lower case letters should be used: b, e, o, x.
Wicked Logic's profile photoMark Bridge's profile photoIvan Pierre's profile photoАнатолий Демидович's profile photo
Agreed. O was not a great choice.

Douglas Crockford

Shared publicly  - 
Using this is like pair programming with Abbott and Costello.
Rob Seaver's profile photoJohn Masse's profile photo

Douglas Crockford

Shared publicly  - 
The truth is, Americans are as likely to be killed by their own furniture falling on them as they are by terrorists. Lightning is more likely to strike you than a terrorist attack. You are more likely to die from surgical complications than by a terrorist’s gun. And you are far, far more likely to die in a car crash.
This surveil-everything approach keeps failing, but we can't ever seem to get enough.
Cliff Dove's profile photoCharles Fulnecky's profile photo

Douglas Crockford

Shared publicly  - 
I was invited to speak at London JS next month, but the organizers have not arranged transportation for me. I have written them three times and they have not responded.

Do any of you know those people? Could you please reach out to them?
London JS ConfSpring 2015. Get Your Ticket. Join us for two days of amazing talks, people, parties and a splash of science. On the February 12th to February 13th we'll be going to The Royal Institution, the home of the electric motor and the laser to host the third London JS Conf.
Andrei Cimpean's profile photoDouglas Crockford's profile photoMargaret Leber's profile photo
Thanks, Andrei. Good to know.
The Boss of You
  • PayPal
Basic Information
_ __ ___ ____ _____ In the Twenty First Century!
On the internet, nobody knows you're a Doug.
Bragging rights
I discovered the JSON Data Interchange Format. I also discovered that JavaScript has good parts. That was the first important discovery of the 21st Century.
Map of the places this user has livedMap of the places this user has livedMap of the places this user has lived
San Jose