1
+ //JavaScript variables can hold different data types: numbers, strings, objects and more, there are a lot of data types.
2
+ let length = 16 ; // Number
3
+ let lastName = "Johnson" ; // String
4
+ let x = { firstName :"John" , lastName :"Doe" } ; // Object
5
+
6
+ //Javascript is not a statically types language, therefore you can add different data types to each other
7
+ //for example:
8
+
9
+ let number = 5 ;
10
+ let text = "test"
11
+ let result = number + text ;
12
+ //this will result in '5test'
13
+ //since the number variable is converted to string before the addition
14
+
15
+ //JavaScript evaluates expressions from left to right. Different sequences can produce different results:
16
+
17
+ let x = 20 + 5 + "New Text"
18
+ //This will result '25New Text'
19
+
20
+
21
+ //Also Javascript types are dynamic
22
+ //So you can do things like
23
+
24
+ let variable ;
25
+ variable = 105 ;
26
+ variable = "Name"
27
+ variable = false ;
28
+
29
+
30
+ //You can write strings with both double (") and single (') quotes and also if you write string templates, you can use backtics (`)
31
+ let string1 = "string1"
32
+ let string2 = 'string2'
33
+ let stringe = `string3`
34
+
35
+ //There are also numbers, where you can choose to write decimals or not
36
+ //such as
37
+
38
+ let number1 = 15 ;
39
+ let number2 = 15.00 ;
40
+
41
+ //or you can write numbers with scientific notation:
42
+ let y = 123e5 ; // 12300000
43
+ let z = 123e-5 ; // 0.00123
44
+
45
+ //Booleans
46
+ //there are 2 values for booleans, true and false
47
+ let bool1 = true
48
+ let bool2 = false
49
+
50
+ //you can use operators on other datatypes in order to return boolean values
51
+
52
+ let bool3 = 5 < 6 //true
53
+ let bool4 = 2 ^ 2 == 3 //false
54
+
55
+ //Arrays
56
+ //you can initiate arrays with `[]`
57
+
58
+ let array1 = [ 1 , 2 , 3 ]
59
+ //or make empty arrays:
60
+ let array2 = [ ] ;
61
+
62
+ //arrays can contain different data types
63
+
64
+ let array3 = [ 1 , "true" , false ]
65
+
66
+ //Objects are written like
67
+ //they're very similar to how JSON is stored.
68
+ const person = { firstName :"John" , lastName :"Doe" , age :50 , eyeColor :"blue" } ;
69
+
70
+
71
+ //source gathered from https://www.w3schools.com/js/js_datatypes.asp
0 commit comments