Skip to content

Commit 71f7480

Browse files
committed
data types
1 parent 2fe74e4 commit 71f7480

File tree

1 file changed

+43
-28
lines changed

1 file changed

+43
-28
lines changed

ts/index.ts

Lines changed: 43 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,46 @@ console.log(num1);
3636
let character:string = "Typescript";
3737
console.log(character);
3838

39+
// `boolean`: Represents a true or false value.
40+
let isAvailable :boolean= true;
3941

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"];
4046

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
4151

52+
// `null`: Represents intentional absence of a value.
53+
let val1:null=null;
4254

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';
4379

4480

4581

@@ -76,25 +112,16 @@ console.log(character);
76112

77113

78114
/*
79-
3. `boolean`: Represents a true or false value.
80-
Example: let isActive: boolean = true;
115+
3. `boolean`
81116
*/
82117

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-
*/
89118

90-
// let empty: null = null; // Example: null
91119

92120
/*
93-
5. `undefined`: Represents a declared variable without a value assigned.
94-
Example: let uninitialized: undefined;
95-
*/
121+
4. `null`
96122
97-
// let uninitialized: undefined; // Example: undefined
123+
/*
124+
5. `undefined`
98125
99126
/*
100127
6. `symbol`: Represents a unique identifier.
@@ -112,18 +139,10 @@ console.log(character);
112139
// ==============================
113140

114141
/*
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`
120143
121144
/*
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`
127146
128147
/*
129148
3. `function`: Represents a callable function.
@@ -133,11 +152,7 @@ console.log(character);
133152
// let greet: (name: string) => string = (name) => "Hello, " + name; // Example: function
134153

135154
/*
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`
141156
142157
// ==============================
143158
// 📚 3. Special Types

0 commit comments

Comments
 (0)