You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: tutorials/learn-js.org/en/Variables and Types.md
+10-10Lines changed: 10 additions & 10 deletions
Original file line number
Diff line number
Diff line change
@@ -5,9 +5,9 @@ Like almost every dynamic language, JavaScript is a "duck-typed" language, and t
5
5
6
6
We can define several types of variables to use in our code:
7
7
8
-
var myNumber = 3; // a number
9
-
var myString = "Hello, World!" // a string
10
-
var myBoolean = true; // a boolean
8
+
const myNumber = 3; // a number
9
+
const myString = "Hello, World!" // a string
10
+
const myBoolean = true; // a boolean
11
11
12
12
A few notes about variable types in JavaScript:
13
13
@@ -16,19 +16,19 @@ A few notes about variable types in JavaScript:
16
16
17
17
There are two more advanced types in JavaScript. An array, and an object. We will get to them in more advanced tutorials.
18
18
19
-
var myArray = []; // an array
20
-
var myObject = {}; // an object
19
+
const myArray = []; // an array
20
+
const myObject = {}; // an object
21
21
22
22
On top of that, there are two special types called `undefined` and `null`.
23
23
24
24
When a variable is used without first defining a value for it, it is equal to undefined. For example:
25
25
26
-
var newVariable;
26
+
const newVariable;
27
27
console.log(newVariable); //prints undefined
28
28
29
29
However, the `null` value is a different type of value, and is used when a variable should be marked as empty. `undefined` can be used for this purpose, but it should not be used.
30
30
31
-
var emptyVariable = null;
31
+
const emptyVariable = null;
32
32
console.log(emptyVariable);
33
33
34
34
@@ -59,9 +59,9 @@ myBoolean is equal to false
59
59
60
60
Solution
61
61
--------
62
-
var myNumber=4;
63
-
var myString="Variables are great.";
64
-
var myBoolean=false;
62
+
const myNumber=4;
63
+
const myString="Variables are great.";
64
+
const myBoolean=false;
65
65
console.log("myNumber is equal to " + myNumber);
66
66
console.log("myString is equal to " + myString);
67
67
console.log("myBoolean is equal to " + myBoolean);
0 commit comments