JavaScript QuickStart: Rules of JavaScript

JavaScript QuickStart: Rules of JavaScript

ike any other language, be it English, Japanese, Pascal, or C++, JavaScript has some basic grammar rules. Understanding these helps you “read” the script and write your own scripts. The most common scripting errors are often simple gramatical errors.

JavaScript Grammar Rules

  • Capitalization Counts
  • JavaScript is case-sensitive
  • In a JavaScript script, capitalization matters; when writing a JavaScript script, be aware of upper and lower case characters:


    is not the same as


    Use Matching Pairs

  • Opening symbols need matching closing symbols.
  • In a JavaScript script, open and closed symbols need to work in pairs. A very common error is to omit or misplace one part of the pair.

    Sometimes you’ll use braces to set apart information. Every open brace needs a matching closing brace, like this:

    { information }

    Sometimes you’ll use a set of parenthesis characters to contain information. Every open character needs a matching closed character, like this:

    ( information )
    Sometimes you’ll use single or double quotes. Every single and double quote needs to have matching single or double ending quote marks, like this:
    ‘dogs’ or “cats”

    When you are nesting items, matching pairs become even more essential; they sort the information that belongs together, like this:

    (this information and (that and that) together)

    Use White Space As Needed

  • JavaScript ignores extras spaces.
  • Like HTML, JavaScript ignores extra white space. In a JavaScript script, you can add extra spaces or tabs to make your script text files easier to read and edit. For example, these equations will do the same thing?put a container in the variable named sendLetter. The first is just a little easier to read:

    sendLetter = visits + 3


    Use Comments
    Comment lines are places for you to make notes to yourself about what the script is doing or when the script was created and by whom. Read the comments you find in a script. They’ll help you understand what is going on. And when you write or edit a script, put in your own comments. It is a good habit, right from the beginning, to add comments.

    Double slashes mark a comment line. Anything between the double slashes (//) and the end-of-line character that is inserted when you press the hard return key is “invisible” to the script.

    This is a the way a comment looks:

    //The next line initializes a counter

    You can also create a comment block. The block starts with a /* and ends with an */, like this:

    This is a comment block. You can put many lines of text together within a block to explain what the script is doing. It is a good idea to make comments about your script so that you can later make edits or changes as necessary.

    See the next section “Next Steps: Getting Your Hands Dirty.”


    About Our Editorial Process

    At DevX, we’re dedicated to tech entrepreneurship. Our team closely follows industry shifts, new products, AI breakthroughs, technology trends, and funding announcements. Articles undergo thorough editing to ensure accuracy and clarity, reflecting DevX’s style and supporting entrepreneurs in the tech sphere.

    See our full editorial policy.

    About Our Journalist