-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy path1-variables.ts
More file actions
37 lines (26 loc) · 1.05 KB
/
1-variables.ts
File metadata and controls
37 lines (26 loc) · 1.05 KB
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
//We use ":" to assing a type
let number1: number;
let total: number;
//Typescript can inference the type depending on the value set.
//In this case you don't need to specify the type
let percentage = 100;
//you can create constant setting the value after assign the type
const messageResult: string = "The current percentage is:";
//you cannot assign a new value to a constant. uncomment and see the the error in the following line:
//messageResult = ""
//Set a value to the variable
number1 = 0.263;
total = number1 * percentage;
//If you try to set a string value to number1 you will get and error and this is a benefit of usign TypeScript
//Uncomment the code and try
//number1 = "This message";
console.log(`${messageResult} ${total}`);
//TypeScript supports boolean type. This value can be true or false
let IsADeveloper: boolean;
IsADeveloper = true;
console.log(`"Is the user a developer? " ${IsADeveloper}`);
//A variable can have multiples types
let chapterName : string | number;
chapterName = "Number 1";
chapterName = 1;
console.log(chapterName);