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

    Share the Post:
    data observability

    Data Observability Explained

    Data is the lifeblood of any successful business, as it is the driving force behind critical decision-making, insight generation, and strategic development. However, due to its intricate nature, ensuring the

    Heading photo, Metadata.

    What is Metadata?

    What is metadata? Well, It’s an odd concept to wrap your head around. Metadata is essentially the secondary layer of data that tracks details about the “regular” data. The regular

    XDR solutions

    The Benefits of Using XDR Solutions

    Cybercriminals constantly adapt their strategies, developing newer, more powerful, and intelligent ways to attack your network. Since security professionals must innovate as well, more conventional endpoint detection solutions have evolved