Is block style really this important?

Posted by Jack Roscoe on Stack Overflow See other posts from Stack Overflow or by Jack Roscoe
Published on 2010-06-09T09:18:54Z Indexed on 2010/06/09 9:22 UTC
Read the original article Hit count: 271

Filed under:

I just watched a video of Douglas Crockford's presentation about his 2009 book JavaScript: The Good Parts.

In the video, he explains that the following block is dangerous because it produces silent errors:

return
{
    ok: false
};

And that it should actually be written like this (emphasising that although seemingly identical the behavioural difference is crucial):

return {
    ok: false
};

You can see his comments around 32 minutes into the video here: http://www.youtube.com/watch?v=hQVTIJBZook&feature=player_embedded#!&start=1920

I have not heard this before, and was wondering if this rule still applies or if this requirement in syntax has been overcome by JavaScript developments since this statement was made.

I found this very interesting as I have NOT been writing my code this way, and wanted to check that this information was not out of date.

© Stack Overflow or respective owner

Related posts about JavaScript