0 added
0 removed
Original
2026-01-01
Modified
2026-03-09
1
<h2>Commands</h2>
1
<h2>Commands</h2>
2
<p>Every program is a set of commands. In JavaScript, the commands are separated by a semicolon, ;</p>
2
<p>Every program is a set of commands. In JavaScript, the commands are separated by a semicolon, ;</p>
3
<p>The program is executed sequentially, from top to bottom, command after command.</p>
3
<p>The program is executed sequentially, from top to bottom, command after command.</p>
4
<p>The code inside the comments is not executed. Examples of comments:</p>
4
<p>The code inside the comments is not executed. Examples of comments:</p>
5
// This line of code will not be executed. Single-line comment. /* These lines of code will not be executed. This is a multi-line comment. */<p>The console.log() command can be used anywhere in the program. It can return numbers, strings (they must be expressed in quotes), results of some operations.</p>
5
// This line of code will not be executed. Single-line comment. /* These lines of code will not be executed. This is a multi-line comment. */<p>The console.log() command can be used anywhere in the program. It can return numbers, strings (they must be expressed in quotes), results of some operations.</p>
6
<h2>Variables</h2>
6
<h2>Variables</h2>
7
<p>A variable is a name for data that is understandable to people.</p>
7
<p>A variable is a name for data that is understandable to people.</p>
8
<p>You can create a variable with the var command followed by the name of the variable. You can write the name using the camelCase style:</p>
8
<p>You can create a variable with the var command followed by the name of the variable. You can write the name using the camelCase style:</p>
9
var myNumber; var userName;<p>or snake_case:</p>
9
var myNumber; var userName;<p>or snake_case:</p>
10
var my_number; var my_name;<p>Variable names in JavaScript are case sensitive: myname and myName are two different variables.</p>
10
var my_number; var my_name;<p>Variable names in JavaScript are case sensitive: myname and myName are two different variables.</p>
11
<p>The variable name must begin with a Latin letter and can only contain Latin letters and numbers.</p>
11
<p>The variable name must begin with a Latin letter and can only contain Latin letters and numbers.</p>
12
<p>You cannot use special keywords such as var or if as the name of the variable. Here is the<a>Full List</a>of these keywords.</p>
12
<p>You cannot use special keywords such as var or if as the name of the variable. Here is the<a>Full List</a>of these keywords.</p>
13
<p>The var command is used only once to create each variable. We then access the variable by its name, without var.</p>
13
<p>The var command is used only once to create each variable. We then access the variable by its name, without var.</p>
14
<p>To assign a value to the variable, use the equal sign =.</p>
14
<p>To assign a value to the variable, use the equal sign =.</p>
15
<p>After the variable is created, it can be used in other commands, for example, it can be logged in the console.</p>
15
<p>After the variable is created, it can be used in other commands, for example, it can be logged in the console.</p>
16
<p>If a new value is assigned to the declared variable with a value, it will override the old value. This is called overriding the value of a variable.</p>
16
<p>If a new value is assigned to the declared variable with a value, it will override the old value. This is called overriding the value of a variable.</p>
17
var milkInGrams = 20; console.log(milkInGrams); // Logs 20 milkInGrams = 100; console.log(milkInGrams); // Logs 100<h2>Operations</h2>
17
var milkInGrams = 20; console.log(milkInGrams); // Logs 20 milkInGrams = 100; console.log(milkInGrams); // Logs 100<h2>Operations</h2>
18
<p>Examples of operations: addition (+), subtraction (-), multiplication (*), division (/).</p>
18
<p>Examples of operations: addition (+), subtraction (-), multiplication (*), division (/).</p>
19
<p>Variables can be part of the operations:</p>
19
<p>Variables can be part of the operations:</p>
20
milkInGrams * 0.5;<p>You can use parentheses to change the priority of operations</p>
20
milkInGrams * 0.5;<p>You can use parentheses to change the priority of operations</p>
21
var firstNumber = 100 + 50 / 2; var secondNumber = (100 + 50) / 2;<p>If a string is involved in the addition operation, the result will be presented as a string:</p>
21
var firstNumber = 100 + 50 / 2; var secondNumber = (100 + 50) / 2;<p>If a string is involved in the addition operation, the result will be presented as a string:</p>
22
console.log('Milk, g: ' + 50); // Logs 'Milk, g: 50'<p>Addition of strings is concatenation.</p>
22
console.log('Milk, g: ' + 50); // Logs 'Milk, g: 50'<p>Addition of strings is concatenation.</p>
23
<a>Continue</a>
23
<a>Continue</a>