@@ -36,10 +36,46 @@ console.log(num1);
36
36
let character :string = "Typescript" ;
37
37
console . log ( character ) ;
38
38
39
+ // `boolean`: Represents a true or false value.
40
+ let isAvailable :boolean = true ;
39
41
42
+ //`array`: Represents an ordered list of elements of a specific type.
43
+ //let numArray: type[]
44
+ let numArray : number [ ] = [ 1 , 2 , 3 , 4 ] ;
45
+ let CharArray :string [ ] = [ "a" , "b" , "g" ] ;
40
46
47
+ // `undefined`: Represents a declared variable without a value assigned.
48
+ //let val: undefined=1; ---error
49
+ let val :undefined = undefined ;
50
+ //val=1;--error
41
51
52
+ // `null`: Represents intentional absence of a value.
53
+ let val1 :null = null ;
42
54
55
+ //`object`: Represents any non-primitive type (anything except `number`, `string`, `boolean`, `null`, `undefined`, `symbol`, `bigint`).
56
+ let person : object = { name : "John" , age : 30 } ;
57
+ let obj :{ name :string , age :number } = {
58
+ name :"abc" ,
59
+ age :10
60
+ } ;
61
+
62
+ //spread operator
63
+ let obj1 = { ...obj } ;
64
+ console . log ( obj1 ) ;
65
+
66
+ //replace
67
+ obj = { ...obj , age :44 , name :"shreya" } ;
68
+ console . log ( obj ) ;
69
+
70
+
71
+
72
+ // `tuple`: Represents a fixed-size, ordered collection of elements of possibly different types.
73
+ let valArray :[ number , string ] = [ 1 , 'a' ] ;
74
+
75
+ //`any`: Represents any type, disabling type checking. Used when the type is unknown or not important.
76
+ let numVal ;
77
+ numVal = 1 ;
78
+ numVal = 'a' ;
43
79
44
80
45
81
@@ -76,25 +112,16 @@ console.log(character);
76
112
77
113
78
114
/*
79
- 3. `boolean`: Represents a true or false value.
80
- Example: let isActive: boolean = true;
115
+ 3. `boolean`
81
116
*/
82
117
83
- // let isActive: boolean = true; // Example: boolean
84
-
85
- /*
86
- 4. `null`: Represents intentional absence of a value.
87
- Example: let empty: null = null;
88
- */
89
118
90
- // let empty: null = null; // Example: null
91
119
92
120
/*
93
- 5. `undefined`: Represents a declared variable without a value assigned.
94
- Example: let uninitialized: undefined;
95
- */
121
+ 4. `null`
96
122
97
- // let uninitialized: undefined; // Example: undefined
123
+ /*
124
+ 5. `undefined`
98
125
99
126
/*
100
127
6. `symbol`: Represents a unique identifier.
@@ -112,18 +139,10 @@ console.log(character);
112
139
// ==============================
113
140
114
141
/*
115
- 1. `object`: Represents any non-primitive type (anything except `number`, `string`, `boolean`, `null`, `undefined`, `symbol`, `bigint`).
116
- Example: let person: object = { name: "John", age: 30 };
117
- */
118
-
119
- // let person: object = { name: "John", age: 30 }; // Example: object
142
+ 1. `object`
120
143
121
144
/*
122
- 2. `array`: Represents an ordered list of elements of a specific type.
123
- Example: let numbers: number[] = [1, 2, 3, 4];
124
- */
125
-
126
- // let numbers: number[] = [1, 2, 3, 4]; // Example: array
145
+ 2. `array`
127
146
128
147
/*
129
148
3. `function`: Represents a callable function.
@@ -133,11 +152,7 @@ console.log(character);
133
152
// let greet: (name: string) => string = (name) => "Hello, " + name; // Example: function
134
153
135
154
/*
136
- 4. `tuple`: Represents a fixed-size, ordered collection of elements of possibly different types.
137
- Example: let point: [number, number] = [10, 20];
138
- */
139
-
140
- // let point: [number, number] = [10, 20]; // Example: tuple
155
+ 4. `tuple`
141
156
142
157
// ==============================
143
158
// 📚 3. Special Types
0 commit comments