Live data from Hacker News

The best JavaScript guide ever

developer.mozilla.org

11–20 of 56 posts

Re: The best JavaScript guide ever

#11

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/

I agree. Eloquent Javascript is excellent.

At least in Google Chrome on a Mac, all I get are blank white pages. If I hit view source, then I see text, but otherwise I see no text.

Re: The best JavaScript guide ever

#12

Earlier quoted context omitted.

I agree. Eloquent Javascript is excellent.

At least in Google Chrome on a Mac, all I get are blank white pages. If I hit view source, then I see text, but otherwise I see no text.

I just checked in Chrome 6 on Mac OS X 10.6.4 -- works fine here. In Safari 5 Mac as well.

Re: The best JavaScript guide ever

#13
post #5

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

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.

Re: The best JavaScript guide ever

#14

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/

And Marijn developed Postmodern for Lisp Postgres access too!

Re: The best JavaScript guide ever

#15
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).

Re: The best JavaScript guide ever

#16
post #6
post #2

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

...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…

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.

Re: The best JavaScript guide ever

#17
post #15

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 b…

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]

Re: The best JavaScript guide ever

#18
post #7
post #3

Earlier quoted context omitted.

Good point. I'll update the title. [edit] title updated

Please read http://ycombinator.com/newsguidelines.html and edit accordingly. Something like "The Mozilla Developer Center's JavaScript Guide" would be a good title.

I think the title is fine as it is now ... makes it clear that this isn't just another JavaScript guide/tutorial.

Re: The best JavaScript guide ever

#19
post #15

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 b…

    var a = x:1
This is invalid. Stop guessing. Read the language spec. Best by far is "Definitive Javascript O'Reilly"

{} is a block of statements. For example,

  {doSomething();doAnotherThing()}
{} when used as an expression, is object literal notation. For example,

  var a = {foo:23,bar:99};
If you want to be explicit that something is an expression, enclose it in parenthesis...

  Console>{foo:1}
  1                // "{}" = code block, "foo:" = label.

  Console>({foo:1})
  {foo:1}
Return an object:

  function foo() {
    return {bar:23, baz: function() {return 89}};
  }

Re: The best JavaScript guide ever

#20
post #7

Earlier quoted context omitted.

Please read http://ycombinator.com/newsguidelines.html and edit accordingly. Something like "The Mozilla Developer Center's JavaScript Guide" would be a good title.

I think the title is fine as it is now ... makes it clear that this isn't just another JavaScript guide/tutorial.

I disagree. The title is against HN's posting guidelines. It's also not unanimous, as even in the comments here people have suggested other ways to learn JS that they feel are superior.

Noting in the title that this is Mozilla's JS reference is enough to give it credence and is still objective.

Post reply on HN