-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdatatypes.js
44 lines (44 loc) · 942 Bytes
/
datatypes.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
"use strict";
// String
let lname;
lname = "John";
// Capitalizated
let newName = lname.toUpperCase();
console.log(newName);
// Number
let age;
age = 24;
age = 25.5;
let num = "23";
let result = parseInt(num);
// Boolean
let isValid = false;
console.log(isValid);
// Array
// String array
let array;
array = ["John", "Nick", "Doe", "Chris"];
let arrayResult3 = array.find((name) => name === "John");
console.log(arrayResult3);
// Number array
let array2;
array2 = [1, 2, 3, 4, 5];
let arrayResult = array2.filter((num) => num > 2);
let arrayResult2 = array2.find((num) => num === 2);
let arrayResult4 = array2.reduce((acc, num) => acc + num);
console.log(arrayResult);
console.log(arrayResult2);
console.log(arrayResult4);
let c = 2 /* Color.Blue */;
// tuple
let swapNumbers;
function swapNumber(num1, num2) {
return [num1, num2];
}
swapNumbers = swapNumber(10, 20);
swapNumbers[0];
swapNumbers[1];
// any
let dep;
dep = "it";
dep = 20;