JavaScript Syntax

JavaScript can be place the <script> labels, containing your JavaScript, anyplace inside your site page, yet it is ordinarily suggested that we should keep it inside the <head> tags.


<script ...> 

JavaScript code 

The content label takes two critical properties − Language

JavaScript Programs

A computer program is a rundown of "instructions" to be "executed" by the computer.

In a programming language, these program directions are called statements.

JavaScript is a programming language.

JavaScript articulations are isolated by semicolons.


<script> var x = 4;
var y = 3;
var z = x + y; </script>
Try it Yourself »

JavaScript Statements

JavaScript proclamations are formed of:

Values, Operators, Expressions, Keywords, what's more, Comments.

JavaScript Values

The JavaScript sentence structure characterizes two sorts of qualities: Fixed qualities and variable values.

Fixed values are called literals. Variable qualities are called variables.

JavaScript Literals

The most imperative guidelines for composing fixed qualities are:

Numbers are composed with or without decimals:


Try it Yourself »

Strings are content, composed inside twofold or single quotes:



JavaScript Variables

In a programming language, variables are utilized to store information values.

JavaScript utilizes the var watchword to declare variables.

An equal sign is utilized to assign values to variables.

In this model, x is characterized as a variable. At that point, x is appointed (given) the esteem 8:

<script> var x;

x = 8;
</script> Try it Yourself »

JavaScript Operators

JavaScript utilizes a assignment operator ( = ) to assign qualities to factors:

var x = 6;
var y = 8;
Try it Yourself »

JavaScript utilizes arithmetic operators ( + - * /) to compute values:

(12 + 3) * 4
Try it Yourself »

JavaScript Expressions

An articulation is a mix of qualities, factors, and administrators, which processes to a value.

The calculation is called an evaluation.

For precedent, 6* 18 assesses to 108:

Expressions can likewise contain variable values:

x * 10

The qualities can be of different sorts, for example, numbers and strings.

For model, "John" + " " + "Doe", assesses to "John Doe":

"Moriss" + " " + "Son"

JavaScript Keywords

JavaScript keywords are utilized to distinguish activities to be performed.

The var watchword advises the program to make another variable:

<script>var x = 4 + 5;
var y = x * 50;</script>
Try it Yourself »

JavaScript Comments

Not all JavaScript articulations are "executed".

Code after twofold cuts // or between /* and */ is treated as a comment.

Comments are overlooked, and won't be executed:

<script> var x = 8;  /I will be executed

//var x = 3;   I will NOT be executed</script>
Try it Yourself »

JavaScript Identifiers

Identifiers are names.

In JavaScript, identifiers are utilized to name factors (and catchphrases, and capacities, and labels).

The rules for lawful names are much the equivalent in most programming languages.

In JavaScript, the principal character must be a letter, an underscore (_), or a dollar sign ($).

Subsequent characters might be letters, digits, underscores, or dollar signs.

JavaScript is Case Sensitive

All JavaScript identifiers are case sensitive

The factors lastName and lastname, are two diverse variables.

lastName = "Doe";
lastname = "Peterson";
Try it Yourself »

JavaScript does not translate VAR or Var as the watchword var.

JavaScript and Camel Case

Historically, software engineers have utilized three different ways of joining numerous words into one variable name:


first-name, last-name, ace card, between city.


first_name, last_name, master_card, inter_city.

Camel Case:

FirstName, LastName, MasterCard, InterCity.

In programming dialects, particularly in JavaScript, camel case frequently begins with a lowercase letter:

firstName, lastName, masterCard, interCity.