There is rules that should be considered when developing with JavaScript.

A computer program is instructions written for processing by the computer.

There are different rules for each programming language when writing instructions.

Spelling rules are called syntax.

The smallest piece of code that performs a certain action in JavaScript commands is called code.

JavaScript codes are terminated with semicolons.

var a, b, c;
a = 5;
b = 6;
c = a + b;

JavaScript code consists of variables, operators, statements, keywords, and comments.

Two different types of values can be written in JavaScript, fixed values and variable values.

Fixed Values

Constant values are values written without being stored in any variable.

Fixed-valued numbers are written without any quotation marks.

14.53
1453
alert(14.53);

Fixed-valued strings are written in single or double quotes.

"baransel.dev"
'baransel.dev'
alert("baransel.dev");

Variables

In programming languages, variables are used to store data.

The var keyword is used to declare variables in JavaScript.

The equal sign (=) is used to assign a value to the defined variable.

In the example, x is defined as a variable and then the value 2000 is assigned to the variable x.

var x;
x = 2000;

Operators

Arithmetic operators are used for calculations with JavaScript.

var x;
x = (5 + 1) * 10;
alert(x);

JavaScript Idioms

JavaScript statements are generating a new value with values, variables, and operators.

For example, a new value is obtained by multiplying two values.

alert(5 * 10);

Expressions can take a variable value.

var x;
x = 5;
alert(x * 10);

Expressions can take value in text type.

alert("Hello" + " " + "World");

Keywords

JavaScript keywords are used to give instructions.

The JavaScript var keyword instructs the browser to create a new variable.

var a, b, c;
a = 5;
b = 6;
c = a + b;
alert(c);

Comments

Not all JavaScript code is processed by the browser.

The double slash after //, /* to */ is treated as comment code by the browser.

var x;
x = 5;
// alert(x * 10);

Identifiers

The naming of JavaScript variables, functions, and tags is called identifiers.

Identifier rules are the same as in most programming languages.

The first character of the JavaScript identifier can be a letter, an underscore (_), or a dollar sign ($).

Subsequent characters can be characters, numbers, underscores, or dollar signs.

Case Sensitivity

var world, World;
world = "baransel.dev";
World = "Hello World!";
alert(World);

Separating JavaScript Codes

When writing code with JavaScript, we can separate the codes with semicolons.

var a, b, c;
a = 5;
b = 6;
c = a + b;

JavaScript code can be written on a single line when separated by semicolons.

var a, b, c; a = 5; b = 6; c = a + b;

It is not mandatory to separate JavaScript codes with semicolons.