js syntax keywords, statements, comments, identifiers

Tut#1 JavaScript Syntax: Identifiers, Comments, Statements and Keywords

What do we discuss in this article?

  1. Case-sensitivity
  2. Identifiers
  3. Comments
  4. Statements
  5. Keywords

Syntax means arrangement of words, phrases to create meaningful sentences in any language. In English, Syntax would mean arrangement of nouns, verbs, pronouns, adjectives and adverbs to create meaningful sentences. In JavaScript, it includes the above 4 aspects.

A] Case Sensitivity

Everything is case-sensitive; variables, function names,and operators are all case-sensitive, meaning that a variable named dog is different from a variable named Dog which is also different from another one named dOg. Similarly, typeof can’t be the name of a function, because it’s a keyword , a word having predefined meaning.

B] Identifiers

An identifier is the name of a variable, function, property, or function argument. Identifiers may be one or more characters in the following format:

  • The first character must be a letter, an underscore (_), or a dollar sign ($).
  • All other characters may be letters, underscores, dollar signs, or numbers.
  • Letters in an identifier may include extended ASCII or Unicode letter characters such as À and Æ, though not recommended.
  • ECMAScript identifiers use camel case, meaning that the first letter is lowercase and each additional word is added such that its first alphabet is capital.

C] Comments

Comments= Notes that you add within your code so that you or other developers using your code understand what is going on when you or they open your code 6 months later. JavaScript has 2 types of comments like most other programming languages.

Use // to mark the start of a single line comment.

Use /* */ to mark the start and end of a multi-line comment. Check the example below.

That’s exactly how you are supposed to add notes in your code files for reference later.

D] Statements

In English, each sentence starts with its first letter being capital and ends with a . or !. The same way, in JavaScript each sentence ends with a ; semicolon. In JavaScript, it’s not compulsory to add a semicolon at the end of each statement, however, it’s a good practice to help you deal with other languages as well.

Including semicolons also improves performance in certain situations, because parsers try to correct syntax errors by inserting semicolons where they appear to belong. In simple words, the parser or interpreter that reads your JavaScript code has to do extra work to determine where to put a semicolon if you don’t put one.

E] Keywords

Keywords= a special set of words that have some meaning predefined by JavaScript. Keywords cannot be used as identifiers or property names. Here is a complete list of keywords in JavaScript. The list may change in different versions of JavaScript.