11.) Which TypeScript feature helps in defining a reusable structure for objects?
A) Functions
B) Interfaces
C) Arrays
D) Loops
12.) What is the purpose of TypeScript’s namespace?
A) To define functions
B) To handle exceptions
C) To declare variables
D) To create a module-like structure for code organization
13.) How do you specify a function’s return type in TypeScript?
A) function myFunc(): number { return 10; }
B) function myFunc { return number 10; }
C) function myFunc = (number) => { return 10; }
D) function myFunc -> number { return 10; }
14.) Which of the following is NOT a valid TypeScript data type?
A) string
B) boolean
C) integer
D) number
15.) How do you define an optional property in a TypeScript interface?
A) property: string;
B) property?: string;
C) property! : string;
D) property: string?;
16.) How do you enable strict type checking in TypeScript?
A) By setting “strict”: true in tsconfig.json
B) By using the –strict flag when compiling
C) Both A and B
D) TypeScript does not support strict checking
17.) What is the output of console.log(10 / “2”) in TypeScript?
A) 5
B) “5”
C) NaN
D) Error
18.) Which module system does TypeScript use by default?
A) CommonJS
B) AMD
C) ES6 Modules
D) UMD
19.) What does the never type represent in TypeScript?
A) A variable that can have any value
B) A function that never returns
C) A function that always returns
D) A deprecated feature
20.) How do you explicitly specify a return type of void in TypeScript?
A) function example(): void {}
B) function example() { return void; }
C) function example(): undefined {}
D) function example() -> void {}
Related