tutorialstonight logo


The syntax of any computer language defines how code is written in that language. It is a simple set of rules that is to be followed while writing the code. The combination of these rules give a form to the language.

In this chapter we will discuss syntax of javascript, writing comments, statement, expression, a look at case-sensitivity etc.

Javascript Basic Syntax

These are basics how to define any variable and assign value to them.

Single or multiple variables can be defined in one go. Line terminates with a semicolon ;.

Variable values either can be provided later or can be give while defining variable;

Javascript is case sensitive

In javascript all identifiers like variable, function, class and operators all are case-sensitive.

What does it mean to be case sensitive? Case sensitive means if a variable is defined by the name "Car" then it is different from "car" or "cAr" or "CAR" and so on. All the characters with their case should match to be the same variable or function.

Javascript Comment

Comments are used to add extra information with the code. It is also used to disable code from running.Comment syntax of javascript is shown below.

Whitespace and Semicolon in Javascript

Space, tabs and newlines are considered as whitespace. Unlike other languages javascript has ASI (Automatic Semicolon Insertion) technique which inserts a semicolon at the end of line automatically.

But it is always recommended as to end the line with a semicolon because

  • Putting a semicolon at the end of line makes it more readable.
  • Not giving a semicolon and then giving a new line within the statement may cause error because javascript may find it at the end of the line and will put a semicolon there.
  • In production javascript file are compressed and in absence of semicolons it may cause syntax error.

Javascript Keyword

Javascript keywords are used to identify the task to be done. Like let is used to define a variable, function is used to define any function etc.