Skip to content

Commit 4b274fb

Browse files
committed
added datatypes again
1 parent fd1302f commit 4b274fb

File tree

2 files changed

+89
-0
lines changed

2 files changed

+89
-0
lines changed

data_types/index.html

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
4+
<head>
5+
<meta charset="UTF-8">
6+
<meta http-equiv="X-UA-Compatible" content="IE=edge">
7+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
8+
<link rel="stylesheet" href="app.css">
9+
<title>Data Types</title>
10+
</head>
11+
12+
<body>
13+
<h1>Data Types</h1>
14+
</body>
15+
<script src="main.js"></script>
16+
</body>
17+
18+
</html>

data_types/main.js

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
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

Comments
 (0)