
The best JavaScript guide ever - alrex021
https://developer.mozilla.org/en/JavaScript/Guide
======
Samuel_Michon
I personally prefer programming guides with some humor, lots of examples and
exercises. That's why I recommend Eloquent Javascript by Marijn Haverbeke.

<http://eloquentjavascript.net/>

~~~
marijn
Thanks for the promotion. Made my morning.

~~~
mhansen
Marijn, thanks for writing this. I'm a big fan - I recommend it to my friends
looking to learn JavaScript.

------
kreek
The best way I've found to learn JavaScript is through anything by Douglas
Crawford. 'JavaScript the Good Parts' is especially good.

<http://oreilly.com/catalog/9780596517748>
<http://www.youtube.com/watch?v=hQVTIJBZook>

~~~
kenjackson
I was a Javascript hater for a long time. Douglas turned me around through his
videos and writing. Still not my favorite language, but I have a lot more
respect for it and actually wouldn't mind writing in it if needed.

I also strongly recommend his work for a better understanding of Javascript.

~~~
sysprv
Met Douglas at JAOO (<http://gotocon.com/>) this year; got him to sign my copy
of "JavaScript: The Good Parts" :)

------
revjx
Is this the same Mozilla JS reference that's been kicking around for ages? I
know there seems to be a big campaign to promote JS resources at the moment,
but surely everyone on HN would know about this if they have more than a
passing interest in Javascript or learning it...

~~~
adamhowell
It's on the frontpage of Reddit at the moment, so I assume that's why it's
here, too.

------
wazoox
It is not a tutorial. It's a reference guide.

~~~
dolinsky
...and yet it has 17 points only being posted 16 minutes ago. Is PG working at
all on an algorithm that takes into consideration factors such as the
repetition with which certain accounts vote up a link (or a group of accounts)
and inversely weigh that against other links sumbitted? Possibly implementing
the results via the Fisher Method / Bayesian rank of some kind? As the noise
to signal ratio has widened with HN's popularity I find it harder to see the
'good stuff' bubble to the top.

~~~
dolinsky
Why am I not surprised I'm being downvoted. Links like this, and the response
they get (46 votes now) take away valuable space from fresh, timely and
relevant articles yet HN can just as easily be gamed as Digg/Reddit to allow
this to happen.

------
alexyim
I like John Resig's tutorial: <http://ejohn.org/apps/learn/>

~~~
thisisblurry
I used Resig's a few days ago to quickly fix a bug at work. He really does a
great job of making very complex language constructs understandable and easy
to follow.

------
ez77
A bit off topic: does anybody know why Mozilla uses https for this kind of
open stuff?

------
eel
I do like the content of MDC, but it can be frustrating at times, as it seems
to have broken links (links that go to pages which have had their content
merged into a different page).

Or apparently, on the Processing XML with E4X page, there are errors in the
page: /content/body/div[2]/pre[1]/@function, reference to undefined name
'syntax': line 1, column 1 where every code sample should be.

It's under a CC license, so I am hoping that someone will make a better
interface for the content some day.

------
etherael
This used to be my sole resource for everything javascript, it is actually
very good still but there's a slight catch; beware cross browser compatibility
issues, especially with IE, especially especially with older versions of IE.

------
pyre
Sorry, I must have missed the download/offline option. Care to link me up?

~~~
marijn
<http://eloquentjavascript.net/Eloquent%20JavaScript.zip>

(sorry)

------
Tichy
While we are at it, perhaps somebody could explain this JS gotcha I recently
ran into?

My goal was to return something like {x:1} (an object) from a script. It never
worked. If I type that into a console, it returns "1". If I type x:1 into the
console, it also returns 1. So I guess the "{}" is just interpreted as a
block, returning the value of the x:1 expression. But what does x:1 mean? I am
guessing it might just be a bug in the interpreter? Or when is something an
object, and when just a block? var a = x:1 doesn't work, btw. this.x is also
still undefined after this.

The only way I could return my wanted object was by doing var y = {x:1};y;

(This was supposed to be the return value of a Script in NodeJS, using these
silly values because it was a unit test).

~~~
nfriedly
JavaScript doesn't have blocks. {} is shorthand notation for an object, so you
would want something like

    
    
      function asdf(){
        return {x:1};
      }
    

It's a less verbose way of doing this:

    
    
      function asdf2(){
        var myObj = new Object();
        myObj.x = 1;
        return myObj;
      }
    

Outside of a object written in shorthand notation, x:1 is treated as a label
(x:) followed by a value (1). In general labels are not used in JS, and it's
probably a good idea to avoid them.

Relatedly, to "fake" a block in JS, wrap it in a function:

    
    
      (function(){
        var a = 1;
        // do something with a
      }());
      
      // out side of the "block" a is undefined (or whatever value it was before the "block")
    

[Edited for accuracy and clarity]

~~~
nfriedly
Yes, as several people have mentioned, I should have said block _scope_. JS
does allow for blocks, but they don't work the way the parent was thinking.

You can toss extra curly braces in the code and it is a "block" but unless
they are preceded by an "if", "for", or something similar, they don't do much.
They do not return values and they do not affect variable scope. Functions do
both, hence my last example.

~~~
Tichy
I think my understanding of blocks is fine. "Returning" was the wrong
expression, I meant the value of a script (like the result of an eval). I am
aware of the lack of block scope in JS :-)

~~~
nfriedly
Gotcha, glad you've got it figured out then =]

------
wtn
Would be nice if they allowed you to download a tarball of the whole guide.

