Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6222491
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T08:19:24+00:00 2026-05-24T08:19:24+00:00

I have read Crockford’s JavaScript: The Good Parts and have used his validator JSLint

  • 0

I have read Crockford’s JavaScript: The Good Parts and have used his validator JSLint. I am sometimes left wondering the justification behind his recommendations. Below is a list of examples I want substantiated.


  1. Why does JSLint signal an error if you don’t include "use strict";? [See this SO thread.]

  2. Why should variable declarations within a function be done using a single var? [See this SO thread.]

  3. Why do we need to put a space between function and () in function ()?

  4. Why can’t we use continue?

  5. What is wrong with ++ and --?

  6. Why can’t we use the comma operator , (except in the initialisation and incrementation parts of the for statement)? [See this blog post.]

  7. Why should every single statement end with ;? [See this blog post.]

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T08:19:24+00:00Added an answer on May 24, 2026 at 8:19 am

    Much of the behavior of JSLint is explained on the JSLint instructions page. I will refer to it as the JIP from now on.

    Much of the behavior that is not explained by the JIP is explained by Code Conventions for the JavaScript Programming Language by Crockford. I will refer to it as the CCJPL from now on.

    To go down the list:

    1) Why does JSLint signal an error if you don’t include "use strict";?

    Because strict mode enforces many good practices; JSLint is all about enforcing good practices too, so naturally this is its behavior. Looking at what "use strict" enables helps clarify the matter. I’m simply going down the list of this blog post by Resig, so due credit is given there. I’m not commenting on everything it does because I’m not sure of exact reasoning from Crockford for every feature.

    1. Variables must be declared with var before you can assign a value: this stops implicit globals from appearing. Global variables are considered by Crockford to be evil, and this helps eliminate globals you didn’t explicitly set.
    2. It several restricts eval, which Crockford considers to be evil as per the JIP.
    3. It disables the with statement. This is considered by Crockford to be harmful.

    I only skipped out on two features of strict mode: the delete statement’s behavior being modified and overwriting the arguments variable. I don’t know if Crockford agrees or disagrees with these two things, but given that he helped create the ECMAScript 5 standard, I would lean towards agree.

    2) Why should variable declarations within a function be done using a single var?

    First, any variable that is defined without being declared by var is implicitly global, which, according to the JIP, can “mask misspelled names and other problems.” So, that is the reasoning requiring var.

    As for requiring one var, all variable declarations are hoisted to the top of their scope by the JavaScript engine automatically, so my only guess is that Crockford wishes for the developer to be acutely aware of this behavior. Past that, it’s probably a matter of style. Which do you prefer between the two following pieces of code:

    var a, b, c;
    

    or

    var a; var b; var c;
    

    My guess is that Crockford thinks the multiple vars are ugly there. I agree with him on that point.

    Ironically, as per the CCJPL, he actually suggests having all of the variable declarations on different lines with associated comments. JSLint disagrees with him in this regard!

    3) Why do we need to put a space between function and () in function ()?

    This applies only to anonymous functions. As per the CCJPL, it is because:

    If a function literal is anonymous, there should be one space between
    the word function and the ( (left parenthesis). If the space is
    omited, then it can appear that the function’s name is function, which
    is an incorrect reading.

    When I was in the thick of learning JavaScript, I religiously began following Crockford’s conventions… but the logical part of me says that if you have code that names a function function, it’s probably in dire need of reworking anyways. (Not to mention that in JavaScript, it’s a SyntaxError because function is a keyword.)

    4) Why can’t we use continue?

    To quote the CCJPL:

    It tends to obscure the control flow of the function.

    Not exactly an elaborate answer, but I’ve seen arguments on the internet comparing it to goto. Take that as you will.

    5) What is wrong with ++ and --?

    As is said on the JIP:

    The ++ (increment) and — (decrement) operators have been known to
    contribute to bad code by encouraging excessive trickiness. They are
    second only to faulty architecture in enabling to viruses and other
    security menaces. Also, preincrement/postincrement confusion can
    produce off-by-one errors that are extremely difficult to diagnose.

    6) Why can’t we use the comma operator , (except in the initialisation and incrementation parts of the for statement)?

    Another elaborate explanation from the JIP:

    The comma operator can lead to excessively tricky expressions. It can
    also mask some programming errors.

    This is a real shame, because as the blog post you linked shows, the comma operator can really increase the clarity of code in some situations.

    You will notice a common underlying theme throughout many of Crockford’s conventions: understandable, readable code. This is just another example of that. Many conventions are centered around denying access to ‘tricky’ expressions.

    But I think the real word I’d use to describe some of these expressions would be ‘terse’ — which is not necessarily a bad thing, per se, but it can be evil if used wrongly. Crockford’s conventions sometimes try to smash wrongly-used-terseness by removing some of the tools these expressions use, even if they have legitimate uses in some contexts.

    7) Why should every single statement end with ;?

    To quote the JIP again:

    JavaScript uses a C-like syntax which requires the use of semicolons
    to delimit certain statements. JavaScript attempts to make those
    semicolons optional with a semicolon insertion mechanism. This is
    dangerous because it can mask errors.

    Like C, JavaScript has ++ and — and ( operators which can be prefixes
    or suffixes. The disambiguation is done by the semicolon.

    Usually I find the ‘can mask errors’ part of Crockford’s explanations to be rather broad and vague, but semicolon insertion is really one area where I can agree wholeheartedly. It’s easier to use explicit semicolons after every statement than risk narrowing the dangerous waters of semicolon insertion.

    Here is a classic example of semicolon insertion gone wrong from the Wikipedia page on JavaScript Syntax:

    return
    a + b;
    
    // Returns undefined. Treated as:
    //   return;
    //   a + b;
    

    And if you use an object literal like the code from this blog post (a fairly common style of braces), then it can mess you up too:

    function shoeFactory() {
        return // <--- semicolon inserted here
        {
            shoeSize: 48
        };
    }
    
    var shoe = shoeFactory();
    console.log(shoe); // undefined
    

    Another example from the above Wikipedia article:

    a = b + c
    (d + e).foo()
    
    // Treated as:
    //   a = b + c(d + e).foo();
    

    I’ve never really been perturbed by adding explicit semicolons, either. They come to me very naturally when writing almost any code. In fact, I often catch myself putting semicolons in Python even though they’re not necessary.

    In this case, I agree pretty wholeheartedly with Crockford. I think one debugging session concerning semicolon insertion would probably convince most people that it would be easier just to place them in the code.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have read about Crockford's push for using JavaScript in a more obviously prototypal
I read here (Douglas Crockford) using prototype operator to add methods to Javascript classes
To check if an element is an array in JavaScript, I have always used
I have read that errors.add_to_base should be used for errors associated with the object
I have read through several reviews on Amazon and some books seem outdated. I
I have read a lot that LISP can redefine syntax on the fly, presumably
I have read about partial methods in the latest C# language specification , so
I have read that using database keys in a URL is a bad thing
I have read this post about how to test private methods. I usually do
I have read on Stack Overflow some people that have converting to C#2.0 to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.