Tutorials Tonight's Logo
Follow Us


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;

let a;    // defining single variable
let b, c, d;    // defining multiple variables
a = 10;    // assigning value
let e = 5; // defining variable and giving value together
let f = "Hello", g = "world"; // multiple variable with values
// each line terminates with a semicolon

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.

let Car, car;
Car = "BMW";
car = "Ford"; // Car != car

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.

// this is a single line comment
// console.log("Hello, World!"); ( commenting out code )
/* this is multiline
  comment used to comment out
  multiple line */

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.

let a = 12;
function my_function () {
    do something...

More Learning

Want to learn more about programming and web development? We have a few recommendations for you.

Follow Us

Copyright © Tutorials Tonight. All Rights Are Reserved.