TypeScript is a powerful, open-source language developed by Microsoft that enhances JavaScript with optional static typing. It helps developers catch errors early and build more reliable, scalable applications by providing features like type annotations, interfaces, and advanced tooling.
TypeScript is an open-source programming language developed by Microsoft that builds on JavaScript by adding static types. This means you can define variable types, function parameters, and object properties explicitly, which helps catch errors during development rather than at runtime. TypeScript includes features like classes, interfaces, and generics that enhance JavaScript with more robust, maintainable, and scalable code. It compiles down to plain JavaScript, so it can be used in any JavaScript environment. By providing type safety and tooling support, TypeScript aims to improve developer productivity and code quality, especially in large or complex projects.
APPLY HERE FOR TYPESCRIPT PROFESSIONAL CERTIFICATION
Here are the questions and answers :
1. What is TypeScript?
Options:
A. A superset of Python
B. A library for JavaScript
C. A statically typed superset of JavaScript
D. A new programming language
Answer: C. A statically typed superset of JavaScript
2. Which command is used to compile TypeScript code into JavaScript?
Options:
A. tsc
B. tsc --compile
C. typescript
D. compile-ts
Answer: A. tsc
3. How do you declare a variable with a specific type in TypeScript?
Options:
A. let variableName: type;
B. var variableName = type;
C. const variableName: type;
D. type variableName = value;
Answer: A. let variableName: type;
4. What is the TypeScript type for a string?
Options:
A. string
B. String
C. text
D. str
Answer: A. string
5. Which of the following is a correct way to define a function that takes a number and returns a string?
Options:
A. function myFunction(num: number): string {}
B. function myFunction(num: number) => string {}
C. function myFunction(num: number) -> string {}
D. function myFunction(num: number): String {}
Answer: A. function myFunction(num: number): string {}
6. What does the ‘interface’ keyword do in TypeScript?
Options:
A. Defines a class
B. Defines a type for objects
C. Creates a new module
D. Declares a function
Answer: B. Defines a type for objects
7. How do you declare an optional parameter in a TypeScript function?
Options:
A. function myFunction(param?: type) {}
B. function myFunction(param: type = default) {}
C. function myFunction(param: type!) {}
D. function myFunction(param: type|undefined) {}
Answer: A. function myFunction(param?: type) {}
8. Which operator is used for type assertions in TypeScript?
Options:
A. !
B. as
C. type
D. assert
Answer: B. as
9. What is the purpose of the ‘readonly’ modifier in TypeScript?
Options:
A. To define a method that cannot be overridden
B. To make a property immutable after initialization
C. To restrict the scope of a variable
D. To make a method only available in derived classes
Answer: B. To make a property immutable after initialization
10. Which TypeScript feature allows you to define a function that can take different types of arguments?
Options:
A. Generics
B. Interfaces
C. Tuples
D. Enums
Answer: A. Generics
11. How do you specify the type of an array of numbers in TypeScript?
Options:
A. number[]
B. Array
C. array
D. Both (a) and (b)
Answer: D. Both (a) and (b)
12. What is the default type of variables in TypeScript if not explicitly typed?
Options:
A. any
B. unknown
C. void
D. never
Answer: A. any
13. How do you create a class in TypeScript that implements an interface?
Options:
A. class MyClass implements MyInterface {}
B. class MyClass extends MyInterface {}
C. class MyClass includes MyInterface {}
D. class MyClass uses MyInterface {}
Answer: A. class MyClass implements MyInterface {}
14. What keyword is used to extend a class in TypeScript?
Options:
A. extends
B. inherits
C. super
D. implements
Answer: A. extends
15. What is the correct way to use a tuple in TypeScript?
Options:
A. let myTuple: [number, string] = [1, "hello"];
B. let myTuple: (number, string) = [1, "hello"];
C. let myTuple: [number | string] = [1, "hello"];
D. let myTuple: Array = [1, "hello"];
Answer: A. let myTuple: [number, string] = [1, "hello"];
16. How do you create an enum in TypeScript?
Options:
A. enum Color { Red, Green, Blue }
B. type Color = { Red, Green, Blue }
C. class Color { Red, Green, Blue }
D. interface Color { Red, Green, Blue }
Answer: A. enum Color { Red, Green, Blue }
17. What does the ‘never’ type represent in TypeScript?
Options:
A. Values that are always falsy
B. The absence of any type at all
C. Values that never occur
D. A type that can be any value
Answer: C. Values that never occur
18. How do you declare a type alias in TypeScript?
Options:
A. type AliasName = Type;
B. alias AliasName = Type;
C. typedef AliasName = Type;
D. typeof AliasName = Type;
Answer: A. type AliasName = Type;
19. Which TypeScript keyword allows you to create a read-only property in an interface?
Options:
A. const
B. readonly
C. immutable
D. static
Answer: B. readonly
20. What is the purpose of the ‘type’ keyword in TypeScript?
Options:
A. To create a new object type
B. To define a custom type alias
C. To declare a new class
D. To instantiate an object
Answer: B. To define a custom type alias
Priya Dogra – Certification | Jobs | Internships