

{"id":112940,"date":"2023-05-02T09:00:56","date_gmt":"2023-05-02T03:30:56","guid":{"rendered":"https:\/\/data-flair.training\/blogs\/?p=112940"},"modified":"2023-05-02T17:24:42","modified_gmt":"2023-05-02T11:54:42","slug":"typescript-interview-questions","status":"publish","type":"post","link":"https:\/\/data-flair.training\/blogs\/typescript-interview-questions\/","title":{"rendered":"TypeScript Interview Questions"},"content":{"rendered":"<p>In a TypeScript interview, you may encounter questions that range from basic syntax to more complex concepts like type inference, advanced types, and asynchronous programming. The interviewer may also ask about your experience with TypeScript tooling and how you approach debugging and testing TypeScript code. Check these TypeScripts Interview Questions to learn more.<\/p>\n<h3>TypeScripts Interview Questions<\/h3>\n<p><strong>1. What is the output of the following code?<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">let x = 1;\r\nlet y = '2';\r\nlet z = x + y;\r\nconsole.log(z);\r\n<\/pre>\n<p>Answer &#8211; 12<\/p>\n<p><strong>2. What is the output of the following code?<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">function add(x: number, y: number): number {\r\n return x + y;\r\n}\r\n\r\n\r\nlet result = add(2, '3');\r\nconsole.log(result);\r\n<\/pre>\n<p>Answer &#8211; Type Error<\/p>\n<p><strong>3. What is the output of the following code?<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">class Person {\r\n constructor(private name: string) {}\r\n\r\n getName() {\r\n   return this.name;\r\n }\r\n}\r\n\r\nconst person = new Person('John');\r\nconsole.log(person.getName());\r\nconsole.log(person.name);\r\n<\/pre>\n<p>Answer &#8211; Property &#8216;name&#8217; is private and only accessible within class &#8216;Person&#8217;.<\/p>\n<p><strong>4. What is the output of the following code?<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">let a = [1, 2, 3];\r\nlet b = a.map((x) =&gt; x * 2);\r\nconsole.log(b);\r\n<\/pre>\n<p>Answer &#8211; [2,4,6]<\/p>\n<p><strong>5. What is the output of the following code?<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">const person = {\r\n name: 'John',\r\n age: 30,\r\n};\r\n\r\nconst { name, ...rest } = person;\r\n\r\nconsole.log(name);\r\nconsole.log(rest);\r\n<\/pre>\n<p>Answer &#8211; Cannot redeclare block-scoped variable &#8216;name&#8217;.<\/p>\n<p><strong>6. What is the output of the following code?<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">type Car = {\r\n brand: string;\r\n model: string;\r\n};\r\n\r\ntype Truck = {\r\n brand: string;\r\n model: string;\r\n payload: number;\r\n};\r\n\r\nfunction printVehicle(vehicle: Car | Truck) {\r\n console.log(vehicle.brand + ' ' + vehicle.model);\r\n}\r\n\r\nconst car: Car = { brand: 'Honda', model: 'Civic' };\r\nconst truck: Truck = { brand: 'Ford', model: 'F-150', payload: 1000 };\r\n\r\nprintVehicle(car);\r\nprintVehicle(truck);\r\n<\/pre>\n<p>Answer &#8211;<\/p>\n<p>Honda Civic<br \/>\nFord F-150<\/p>\n<p><strong>7. What is the output of the following code?<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">const numbers = [1, 2, 3, 4, 5];\r\n\r\n\r\nconst evenNumbers = numbers.filter((x) =&gt; x % 2 === 0);\r\nconst doubledNumbers = evenNumbers.map((x) =&gt; x * 2);\r\n\r\n\r\nconsole.log(doubledNumbers);\r\n<\/pre>\n<p>Answer &#8211; [ 4, 8 ]<\/p>\n<p><strong>8. What is the output of the following code?<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">function greet(name?: string) {\r\n console.log('Hello, ' + name ?? 'world!');\r\n}\r\n\r\ngreet();\r\ngreet('John');\r\n<\/pre>\n<p>Answer &#8211;<\/p>\n<p>Hello, undefined<br \/>\nHello, John<\/p>\n<p><strong>9. What is the output of the following code?<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">class Animal {\r\n move(distanceInMeters: number = 0) {\r\n   console.log(`Animal moved ${distanceInMeters}m.`);\r\n }\r\n}\r\n\r\n\r\nclass Dog extends Animal {\r\n bark() {\r\n   console.log('Woof! Woof!');\r\n }\r\n}\r\n\r\nconst dog = new Dog();\r\ndog.bark();\r\ndog.move(10);\r\n<\/pre>\n<p>Answer &#8211;<\/p>\n<p>Woof! Woof!<br \/>\nAnimal moved 10m.<\/p>\n<p><strong>10. What is the output of the following code?<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">type Point = [number, number];\r\n\r\nfunction addPoints(a: Point, b: Point): Point {\r\n return [a[0] + b[0], a[1] + b[1]];\r\n}\r\n\r\nconst point1: Point = [1, 2];\r\nconst point2: Point = [3, 4];\r\nconst sum = addPoints(point1, point2);\r\n\r\nconsole.log(sum);\r\n<\/pre>\n<p>Answer &#8211; [ 4, 6 ]<\/p>\n<p><strong>11. How would you implement a generic function that reverses the order of an array in TypeScript?<\/strong><\/p>\n<p>Answer &#8211;<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">function reverse&lt;T&gt;(array: T[]): T[] {\r\n return array.reverse();\r\n}\r\n\r\nconst numbers = [1, 2, 3];\r\nconst reversedNumbers = reverse(numbers);\r\n<\/pre>\n<p><strong>12. What is a conditional type in TypeScript? Provide an example.<\/strong><\/p>\n<p>Answer &#8211; A conditional type allows you to write a type that depends on a condition. Here&#8217;s an example:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">type IsString&lt;T&gt; = T extends string ? true : false;\r\n\r\nconst result1: IsString&lt;string&gt; = true;\r\nconst result2: IsString&lt;number&gt; = false;\r\n<\/pre>\n<p><strong>13. How would you declare a type that represents an object with a fixed set of properties and their respective types in TypeScript?<\/strong><\/p>\n<p>Answer &#8211; You can use an interface to declare a type that represents an object with a fixed set of properties and their respective types. Here&#8217;s an example:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">interface Person {\r\n name: string;\r\n age: number;\r\n}\r\n\r\nconst person: Person = { name: 'John', age: 30 };\r\n<\/pre>\n<p><strong>14. How would you implement a function that takes a callback as a parameter in TypeScript?<\/strong><\/p>\n<p>Answer &#8211;<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">function runWithCallback(callback: () =&gt; void) {\r\n callback();\r\n}\r\n\r\nrunWithCallback(() =&gt; console.log('Hello, world!'));\r\n<\/pre>\n<p><strong>15. What is the difference between the private, public, and protected access modifiers in TypeScript?<\/strong><\/p>\n<p>Answer- private members can only be accessed within the class they are defined in, public members can be accessed from anywhere, and protected members can be accessed within the class they are defined in and any subclasses that extend that class.<\/p>\n<p><strong>16. How would you declare a type that represents an object with dynamic keys in TypeScript?<\/strong><\/p>\n<p>Answer &#8211;<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">interface DynamicObject {\r\n [key: string]: number;\r\n}\r\n\r\nconst object: DynamicObject = { a: 1, b: 2, c: 3 };\r\n<\/pre>\n<p><strong>17. How would you implement a function that takes an array of values and a predicate function and returns an array of values that pass the predicate in TypeScript?<\/strong><\/p>\n<p>Answer &#8211;<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">function filter&lt;T&gt;(array: T[], predicate: (value: T) =&gt; boolean): T[] {\r\n return array.filter(predicate);\r\n}\r\n\r\nconst numbers = [1, 2, 3, 4, 5];\r\nconst evenNumbers = filter(numbers, (value) =&gt; value % 2 === 0);\r\n<\/pre>\n<p><strong>18. How would you create a function that accepts a variable number of arguments with different types in TypeScript?<\/strong><\/p>\n<p>Answer &#8211;<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">function concatenate(...args: (string | number)[]) {\r\n return args.join('');\r\n}\r\n\r\nconst result = concatenate('hello', 123, 'world');\r\n<\/pre>\n<p><strong>19. How would you create a class in TypeScript that implements multiple interfaces?<\/strong><\/p>\n<p>Answer &#8211;<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">interface Foo {\r\n foo(): void;\r\n}\r\n\r\ninterface Bar {\r\n bar(): void;\r\n}\r\n\r\nclass MyClass implements Foo, Bar {\r\n foo() {\r\n   console.log('foo');\r\n }\r\n\r\n bar() {\r\n   console.log('bar');\r\n }\r\n}\r\n<\/pre>\n<p><strong>20. How would you declare a type that represents a function that returns a Promise in TypeScript?<\/strong><\/p>\n<p>Answer &#8211;<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">type AsyncFunction&lt;T&gt; = () =&gt; Promise&lt;T&gt;;\r\n\r\nconst fetchData: AsyncFunction&lt;string&gt; = async () =&gt; {\r\n const response = await fetch('https:\/\/example.com\/data');\r\n return response.text();\r\n};\r\n<\/pre>\n<p><strong>21. How would you declare a type that represents a function with optional parameters in TypeScript?<\/strong><\/p>\n<p>Answer &#8211;<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">type MyFunction = (a: number, b?: number) =&gt; void;\r\n\r\nconst fn: MyFunction = (a, b) =&gt; {\r\n console.log(a, b);\r\n};\r\n\r\n\r\nfn(1);\r\nfn(1, 2);\r\n<\/pre>\n<p><strong>22. How would you create a type representing a tuple with a fixed number of elements in TypeScript?<\/strong><\/p>\n<p>Answer &#8211;<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">type MyTuple = [string, number];\r\n\r\nconst tuple: MyTuple = ['hello', 123];\r\n<\/pre>\n<p><strong>23. How would you create a type that represents an object with required and optional properties in TypeScript?<\/strong><\/p>\n<p>Answer &#8211;<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">type MyObject = {\r\n requiredProp: string;\r\n optionalProp?: number;\r\n};\r\n\r\ntype MyRequiredObject = Required&lt;MyObject&gt;;\r\n\r\n\r\nconst obj: MyRequiredObject = {\r\n requiredProp: 'hello',\r\n optionalProp: 123,\r\n};\r\n<\/pre>\n<p><strong>24. What is a discriminated union in TypeScript?<\/strong><\/p>\n<p>Answer- A discriminated union is a type that combines several types that have a common, discriminative property. Discriminated unions are commonly used with switch statements and type guards.<\/p>\n<p><strong>25. What is a conditional type in TypeScript?<\/strong><\/p>\n<p>Answer- A conditional type is a type that depends on a condition. Conditional types are commonly used with type inference and type mapping.<\/p>\n<p><strong>26. What is a module in TypeScript?<\/strong><\/p>\n<p>Answer- A module is a way to organize code and encapsulate functionality. Modules can be exported and imported in other modules using the export and import keywords.<\/p>\n<p><strong>27. What is a type predicate in TypeScript?<\/strong><\/p>\n<p>Answer- A type predicate is a function that returns a boolean and is used to narrow the value type. Type predicates are commonly used with conditional types and type guards.<\/p>\n<p><strong>28. What is a type predicate in TypeScript?<\/strong><\/p>\n<p>Answer- A type predicate is a function that returns a boolean and is used to narrow the value type. Type predicates are commonly used with conditional types and type guards.<\/p>\n<p><strong>29. What is the difference between a class and an interface in TypeScript?<\/strong><\/p>\n<p>Answer- A class is a blueprint for creating objects with properties and methods, while an interface is a contract that describes the shape of an object. You can implement an interface in a class, but you cannot implement a class in an interface.<\/p>\n<p><strong>30. What is the output of the following?<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">console.log('a');\r\nsetTimeout(function () {\r\n console.log('b');\r\n}, 0);\r\nconsole.log('c');<\/pre>\n<p>Answer &#8211; The output will be &#8220;a&#8221;, &#8220;c&#8221;, &#8220;b&#8221;.<\/p>\n<p><strong>31. Create a class in TypeScript that represents a car. The car should have a make, model, and year property, as well as a method to start the engine.<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">class Car {\r\n make: string;\r\n model: string;\r\n year: number;\r\n\r\n\r\n constructor(make: string, model: string, year: number) {\r\n   this.make = make;\r\n   this.model = model;\r\n   this.year = year;\r\n }\r\n\r\n startEngine() {\r\n   console.log(`Starting ${this.make} ${this.model}...`);\r\n }\r\n}\r\n\r\nconst myCar = new Car('Toyota', 'Camry', 2022);\r\nmyCar.startEngine(); \/\/ Output: Starting Toyota Camry...<\/pre>\n<p><strong>32. Create a class in TypeScript that represents a person. The person should have a name, age, and email property, as well as a method to introduce themselves.<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">class Person {\r\n name: string;\r\n age: number;\r\n email: string;\r\n\r\n constructor(name: string, age: number, email: string) {\r\n   this.name = name;\r\n   this.age = age;\r\n   this.email = email;\r\n }\r\n\r\n introduce() {\r\n   console.log(\r\n     `Hi, my name is ${this.name}, and I am ${this.age} years old. You can reach me at ${this.email}.`\r\n   );\r\n }\r\n}\r\n\r\nconst john = new Person('John Doe', 25, 'john@example.com');\r\njohn.introduce(); \/\/ Output: Hi, my name is John Doe, and I am 25 years old. You can reach me at john@example.com.\r\n<\/pre>\n<p><strong>33. Create a class in TypeScript that represents a bank account. The account should have a balance property and methods to deposit and withdraw money.<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">class BankAccount {\r\n balance: number;\r\n\r\n\r\n constructor(initialBalance: number) {\r\n   this.balance = initialBalance;\r\n }\r\n\r\n\r\n deposit(amount: number) {\r\n   this.balance += amount;\r\n }\r\n\r\n\r\n withdraw(amount: number) {\r\n   if (amount &gt; this.balance) {\r\n     console.log('Insufficient funds');\r\n     return;\r\n   }\r\n\r\n\r\n   this.balance -= amount;\r\n }\r\n}\r\n\r\nconst myAccount = new BankAccount(1000);\r\nmyAccount.deposit(500);\r\nmyAccount.withdraw(200);\r\nconsole.log(myAccount.balance); \/\/ Output: 1300\r\n<\/pre>\n<p><strong>34. Create a class in TypeScript that represents a calculator. The calculator should have methods to add, subtract, multiply, and divide numbers.<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">class Calculator {\r\n add(a: number, b: number) {\r\n   return a + b;\r\n }\r\n\r\n\r\n subtract(a: number, b: number) {\r\n   return a - b;\r\n }\r\n\r\n\r\n multiply(a: number, b: number) {\r\n   return a * b;\r\n }\r\n\r\n\r\n divide(a: number, b: number) {\r\n   if (b === 0) {\r\n     console.log('Cannot divide by zero');\r\n     return;\r\n   }\r\n\r\n\r\n   return a \/ b;\r\n }\r\n}\r\n\r\n\r\nconst myCalculator = new Calculator();\r\nconsole.log(myCalculator.add(2, 3)); \/\/ Output: 5\r\nconsole.log(myCalculator.subtract(5, 2)); \/\/ Output: 3\r\nconsole.log(myCalculator.multiply(4, 6)); \/\/ Output: 24\r\nconsole.log(myCalculator.divide(10, 2)); \/\/ Output: 5\r\n<\/pre>\n<p><strong>35. Create a class in TypeScript that represents a book. The book should have a title, author, and number of pages property, as well as a method to display its information.<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">class Book {\r\n title: string;\r\n author: string;\r\n pages: number;\r\n\r\n\r\n constructor(title: string, author: string, pages: number) {\r\n   this.title = title;\r\n   this.author = author;\r\n   this.pages = pages;\r\n }\r\n\r\n\r\n displayInfo() {\r\n   console.log(\r\n     `Title: ${this.title}\\nAuthor: ${this.author}\\nNumber of pages: ${this.pages}`\r\n   );\r\n }\r\n}\r\nconst myBook = new Book('The Great Gatsby', 'F. Scott Fitzgerald', 180);\r\nmyBook.displayInfo(); \/\/ Output: Title: The Great Gatsby Author: F. Scott Fitzgerald Number of pages: 180\r\n<\/pre>\n<p><strong>36. Create a class in TypeScript that represents a circle. The circle should have a radius property and methods to calculate its area and circumference.<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">class Circle {\r\n radius: number;\r\n\r\n\r\n constructor(radius: number) {\r\n   this.radius = radius;\r\n }\r\n\r\n\r\n getArea() {\r\n   return Math.PI * this.radius ** 2;\r\n }\r\n\r\n\r\n getCircumference() {\r\n   return 2 * Math.PI * this.radius;\r\n }\r\n}\r\n\r\n\r\nconst myCircle = new Circle(5);\r\nconsole.log(myCircle.getArea()); \/\/ Output: 78.53981633974483\r\nconsole.log(myCircle.getCircumference()); \/\/ Output: 31.41592653589793<\/pre>\n<p><strong>37. Create a class in TypeScript that represents a student. The student should have a name, age, and an array of courses they are taking, as well as a method to display their information.<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">class Student {\r\n name: string;\r\n age: number;\r\n courses: string[];\r\n\r\n\r\n constructor(name: string, age: number, courses: string[]) {\r\n   this.name = name;\r\n   this.age = age;\r\n   this.courses = courses;\r\n }\r\n\r\n\r\n displayInfo() {\r\n   console.log(\r\n     `Name: ${this.name}\\nAge: ${this.age}\\nCourses: ${this.courses.join(\r\n       ', '\r\n     )}`\r\n   );\r\n }\r\n}\r\n\r\n\r\nconst myStudent = new Student('Jane Smith', 20, [\r\n 'Calculus',\r\n 'Physics',\r\n 'Computer Science',\r\n]);\r\nmyStudent.displayInfo(); \/\/ Output: Name: Jane Smith Age: 20 Courses: Calculus, Physics, Computer Science\r\n<\/pre>\n<p><strong>38. Create a class in TypeScript that represents a point in two-dimensional space. The point should have x and y properties and methods to calculate its distance from another point.<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">class Point {\r\n x: number;\r\n y: number;\r\n\r\n\r\n constructor(x: number, y: number) {\r\n   this.x = x;\r\n   this.y = y;\r\n }\r\n\r\n\r\n distanceFrom(point: Point) {\r\n   return Math.sqrt((this.x - point.x) ** 2 + (this.y - point.y) ** 2);\r\n }\r\n}\r\n\r\n\r\nconst pointA = new Point(0, 0);\r\nconst pointB = new Point(3, 4);\r\nconsole.log(pointA.distanceFrom(pointB)); \/\/ Output: 5\r\n<\/pre>\n<p><strong>39. Create a class in TypeScript that represents a shape. The shape should have a name and methods to calculate its area and perimeter.<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">class Shape {\r\n name: string;\r\n\r\n\r\n constructor(name: string) {\r\n   this.name = name;\r\n }\r\n\r\n\r\n getArea() {}\r\n\r\n\r\n getPerimeter() {}\r\n}\r\n\r\n\r\nclass Rectangle extends Shape {\r\n width: number;\r\n height: number;\r\n\r\n\r\n constructor(name: string, width: number, height: number) {\r\n   super(name);\r\n   this.width = width;\r\n   this.height = height;\r\n }\r\n\r\n\r\n getArea() {\r\n   return this.width * this.height;\r\n }\r\n\r\n\r\n getPerimeter() {\r\n   return 2 * (this.width + this.height);\r\n }\r\n}\r\n\r\n\r\nconst myRectangle = new Rectangle('My Rectangle', 5, 10);\r\nconsole.log(myRectangle.getArea()); \/\/ Output: 50\r\nconsole.log(myRectangle.getPerimeter()); \/\/\r\n<\/pre>\n<p><strong>40. Create a class in TypeScript that represents a bank account. The account should have a balance property and methods to deposit and withdraw money.<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">class BankAccount {\r\n balance: number;\r\n\r\n\r\n constructor(initialBalance: number) {\r\n   this.balance = initialBalance;\r\n }\r\n\r\n\r\n deposit(amount: number) {\r\n   this.balance += amount;\r\n }\r\n\r\n\r\n withdraw(amount: number) {\r\n   if (this.balance &gt;= amount) {\r\n     this.balance -= amount;\r\n   } else {\r\n     console.log('Insufficient funds.');\r\n   }\r\n }\r\n}\r\n\r\n\r\nconst myAccount = new BankAccount(100);\r\nconsole.log(myAccount.balance); \/\/ Output: 100\r\nmyAccount.deposit(50);\r\nconsole.log(myAccount.balance); \/\/ Output: 150\r\nmyAccount.withdraw(75);\r\nconsole.log(myAccount.balance); \/\/ Output: 75\r\nmyAccount.withdraw(100); \/\/ Output: Insufficient funds.<\/pre>\n<p><strong>41. Create a function called reverseArray that takes an array of any type and returns a new array with the elements in reverse order.<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">function reverseArray&lt;T&gt;(arr: T[]): T[] {\r\n return arr.reverse();\r\n}\r\n\r\n\r\nconsole.log(reverseArray([1, 2, 3, 4])); \/\/ Output: [4, 3, 2, 1]\r\nconsole.log(reverseArray(['a', 'b', 'c'])); \/\/ Output: [\"c\", \"b\", \"a\"]<\/pre>\n<p><strong>42. Create a function called combineArrays that takes two arrays of the same type and returns a new array with the elements of both arrays concatenated.<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">function combineArrays&lt;T&gt;(arr1: T[], arr2: T[]): T[] {\r\n return arr1.concat(arr2);\r\n}\r\n\r\n\r\nconsole.log(combineArrays([1, 2, 3], [4, 5, 6])); \/\/ Output: [1, 2, 3, 4, 5, 6]\r\nconsole.log(combineArrays(['a', 'b', 'c'], ['d', 'e', 'f'])); \/\/ Output: [\"a\", \"b\", \"c\", \"d\", \"e\", \"f\"]\r\n<\/pre>\n<p><strong>43. Create a function called mapArray that takes an array of any type and a function that maps each element of the array to a new value. The function should return a new array with the mapped values.<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">function mapArray&lt;T, U&gt;(arr: T[], mapper: (item: T) =&gt; U): U[] {\r\n return arr.map(mapper);\r\n}\r\n\r\n\r\nconsole.log(mapArray([1, 2, 3], (x) =&gt; x * 2)); \/\/ Output: [2, 4, 6]\r\nconsole.log(mapArray(['a', 'b', 'c'], (x) =&gt; x.toUpperCase())); \/\/ Output: [\"A\", \"B\", \"C\"]\r\n<\/pre>\n<p><strong>44. Create a class called Stack that uses generics to implement a stack data structure. The class should have methods push and pop to add and remove elements from the stack, as well as a property size that returns the number of elements in the stack.<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">class Stack&lt;T&gt; {\r\n private elements: T[] = [];\r\n\r\n\r\n push(element: T) {\r\n   this.elements.push(element);\r\n }\r\n\r\n\r\n pop(): T | undefined {\r\n   return this.elements.pop();\r\n }\r\n\r\n\r\n get size(): number {\r\n   return this.elements.length;\r\n }\r\n}\r\n\r\n\r\nconst myStack = new Stack&lt;number&gt;();\r\nmyStack.push(1);\r\nmyStack.push(2);\r\nmyStack.push(3);\r\nconsole.log(myStack.pop()); \/\/ Output: 3\r\nconsole.log(myStack.size); \/\/ Output: 2\r\n<\/pre>\n<p><strong>45. Create a function called getObjectProperty that takes an object of type T and a string property name, and returns the value of that property. The function should use a generic type parameter to ensure that the property name is valid for the object type.<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">function getObjectProperty&lt;T, K extends keyof T&gt;(obj: T, key: K): T[K] {\r\n return obj[key];\r\n}\r\n\r\n\r\nconst myObj = { name: 'Jane', age: 30 };\r\nconsole.log(getObjectProperty(myObj, 'name')); \/\/ Output: \"Jane\"\r\nconsole.log(getObjectProperty(myObj, 'age')); \/\/ Output: 30\r\n<\/pre>\n<p><strong>46. Create a module called math that exports a function called add that takes two numbers and returns their sum.<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">export function add(a: number, b: number): number {\r\n return a + b;\r\n}\r\n<\/pre>\n<p>In another file, you can import the add function and use it:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">import { add } from '.\/math';\r\n\r\n\r\nconsole.log(add(1, 2)); \/\/ Output: 3\r\n<\/pre>\n<p><strong>47. Create a module called utilities that exports a class called Logger that logs messages to the console. The class should have a method called log that takes a string message and logs it to the console.<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">export class Logger {\r\n log(message: string) {\r\n   console.log(message);\r\n }\r\n}\r\n<\/pre>\n<p>In another file, you can import the Logger class and use it:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">import { Logger } from '.\/utilities';\r\n\r\n\r\nconst logger = new Logger();\r\nlogger.log('Hello, world!'); \/\/ Output: \"Hello, world!\"\r\n<\/pre>\n<p><strong>48. Create a module called models that exports an interface called User that describes a user object with name and age properties.<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">export interface User {\r\n name: string;\r\n age: number;\r\n}\r\n<\/pre>\n<p>In another file, you can import the User interface and use it:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">import { User } from '.\/models';\r\n\r\n\r\nconst user: User = { name: 'Jane', age: 30 };\r\nconsole.log(user.name); \/\/ Output: \"Jane\"\r\n<\/pre>\n<p><strong>49. Create a module called api that exports a function called fetchData that retrieves data from a remote server. The function should take a URL string and return a Promise that resolves to the response data.<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">export function fetchData(url: string): Promise&lt;any&gt; {\r\n return fetch(url).then((response) =&gt; response.json());\r\n}\r\n<\/pre>\n<p>In another file, you can import the fetchData function and use it:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">import { fetchData } from '.\/api';\r\n\r\n\r\nfetchData('https:\/\/example.com\/data.json').then((data) =&gt; {\r\n console.log(data);\r\n});\r\n<\/pre>\n<p><strong>50. Create a module called config that exports a constant called API_KEY that contains a secret API key. The module should also export a function called getApiKey that returns the value of API_KEY.<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">const API_KEY = 'secret_key';\r\n\r\n\r\nexport function getApiKey(): string {\r\n return API_KEY;\r\n}\r\n<\/pre>\n<p>In another file, you can import the getApiKey function and use it:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">import { getApiKey } from '.\/config';\r\n\r\n\r\nconsole.log(getApiKey()); \/\/ Output: \"secret_key\"\r\n<\/pre>\n<p><strong>51. Write a function getLength that takes a string or an array and returns the length of the string or the array.<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">function getLength(input: string | any[]): number {\r\n return input.length;\r\n}\r\n\r\n\r\nconsole.log(getLength('hello')); \/\/ Output: 5\r\nconsole.log(getLength([1, 2, 3])); \/\/ Output: 3\r\n<\/pre>\n<p><strong>52. Define a type Person that has two properties name and age, where name is a string and age is a number. Then define a type Employee that has three properties name, age, and jobTitle, where jobTitle is a string. Create a union type PersonOrEmployee that can be either a Person or an Employee.<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">type Person = {\r\n name: string;\r\n age: number;\r\n};\r\n\r\n\r\ntype Employee = {\r\n name: string;\r\n age: number;\r\n jobTitle: string;\r\n};\r\n\r\n\r\ntype PersonOrEmployee = Person | Employee;\r\n<\/pre>\n<p><strong>53. Write a function square that takes a number or a string that represents a number and returns the square of the number. If a string is passed, the function should parse it to a number first.<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">function square(input: number | string): number {\r\n const num = typeof input === 'string' ? parseFloat(input) : input;\r\n return num * num;\r\n}\r\n\r\n\r\nconsole.log(square(5)); \/\/ Output: 25\r\nconsole.log(square('7')); \/\/ Output: 49\r\n<\/pre>\n<p><strong>54. Define a type Shape that can be either a Circle or a Rectangle. A Circle has a property radius that is a number, and a Rectangle has properties width and height that are numbers. Create a union type CircleOrRectangle that can be either a Circle or a Rectangle.<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">type Circle = {\r\n kind: 'circle';\r\n radius: number;\r\n};\r\n\r\n\r\ntype Rectangle = {\r\n kind: 'rectangle';\r\n width: number;\r\n height: number;\r\n};\r\n\r\n\r\ntype Shape = Circle | Rectangle;\r\n<\/pre>\n<p><strong>55. Write a function join that takes two strings or two arrays and concatenates them. If both arguments are strings, the function should return a concatenated string. If both arguments are arrays, the function should return a new array that contains the elements of both arrays. And If one argument is a string and the other is an array, the function should throw an error.<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">function join(a: string | any[], b: string | any[]): string | any[] {\r\n if (typeof a === 'string' &amp;&amp; typeof b === 'string') {\r\n   return a + b;\r\n } else if (Array.isArray(a) &amp;&amp; Array.isArray(b)) {\r\n   return [...a, ...b];\r\n } else {\r\n   throw new Error('Arguments must be either both strings or both arrays');\r\n }\r\n}\r\n\r\n\r\nconsole.log(join('hello', 'world')); \/\/ Output: \"helloworld\"\r\nconsole.log(join([1, 2], [3, 4])); \/\/ Output: [1, 2, 3, 4]\r\njoin('hello', [1, 2]); \/\/ Throws an error\r\n<\/pre>\n<p><strong>56. Write a function sum that takes an array of numbers and returns the sum of all the numbers.<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">function sum(numbers: number[]): number {\r\n return numbers.reduce((total, num) =&gt; total + num, 0);\r\n}\r\n\r\n\r\nconsole.log(sum([1, 2, 3]));\r\nconsole.log(sum([4, 5, 6]));\r\n<\/pre>\n<p><strong>57. Define a type Person that has two properties name and age, where name is a string and age is a number. Create an array people that contains three objects of type Person.<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">type Person = {\r\n name: string;\r\n age: number;\r\n};\r\n\r\n\r\nconst people: Person[] = [\r\n { name: 'Alice', age: 25 },\r\n { name: 'Bob', age: 30 },\r\n { name: 'Charlie', age: 35 },\r\n];\r\n<\/pre>\n<p><strong>58. Write a function first that takes an array and returns the first element of the array. If the array is empty, the function should return undefined.<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">function first&lt;T&gt;(array: T[]): T | undefined {\r\n return array.length &gt; 0 ? array[0] : undefined;\r\n}\r\n\r\n\r\nconsole.log(first([1, 2, 3])); \/\/ Output: 1\r\nconsole.log(first([])); \/\/ Output: undefined\r\n<\/pre>\n<p><strong>59. Define a type Animal that has two properties name and species, where both are strings. Create an array animals that contains two objects of type Animal, where one animal is named &#8220;Tom&#8221; and the other is named &#8220;Jerry&#8221;.<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">type Animal = {\r\n name: string;\r\n species: string;\r\n};\r\n\r\n\r\nconst animals: Animal[] = [\r\n { name: 'Tom', species: 'Cat' },\r\n { name: 'Jerry', species: 'Mouse' },\r\n];\r\n<\/pre>\n<p><strong>60. Write a function contains that takes an array and an element, and returns true if the array contains the element, and false otherwise.<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">function contains&lt;T&gt;(array: T[], element: T): boolean {\r\n return array.includes(element);\r\n}\r\n\r\nconsole.log(contains([1, 2, 3], 2)); \/\/ Output: true\r\nconsole.log(contains([4, 5, 6], 1)); \/\/ Output: false\r\n<\/pre>\n<h3>Conclusion<\/h3>\n<p>In conclusion, TypeScript has become an essential tool for web developers who want to build complex and scalable applications. Its static type checking, advanced features, and compatibility with popular frontend frameworks make it a valuable skill to have in the current job market. Therefore, preparing for a TypeScript interview is crucial to demonstrating your knowledge of TypeScript syntax, concepts, and applications.<\/p>\n<p>In addition to mastering TypeScript fundamentals, you may also need to showcase your experience with TypeScript tooling, debugging, and testing, as well as your understanding of how TypeScript integrates with popular frameworks like Angular and React. By investing time in studying and practicing TypeScript, you can position yourself as a skilled TypeScript developer who can deliver high-quality, scalable, and maintainable applications.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In a TypeScript interview, you may encounter questions that range from basic syntax to more complex concepts like type inference, advanced types, and asynchronous programming. The interviewer may also ask about your experience with&#46;&#46;&#46;<\/p>\n","protected":false},"author":581,"featured_media":113160,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[27319],"tags":[27371,27370],"class_list":["post-112940","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-typescript-tutorials","tag-typescript-interview-questions","tag-typescript-interview-questions-and-answers"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.4 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>TypeScript Interview Questions - DataFlair<\/title>\n<meta name=\"description\" content=\"TypeScript has become essential tool for web developers to build complex &amp; scalable applications. Check these TypeScript interview questions.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/data-flair.training\/blogs\/typescript-interview-questions\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"TypeScript Interview Questions - DataFlair\" \/>\n<meta property=\"og:description\" content=\"TypeScript has become essential tool for web developers to build complex &amp; scalable applications. Check these TypeScript interview questions.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/data-flair.training\/blogs\/typescript-interview-questions\/\" \/>\n<meta property=\"og:site_name\" content=\"DataFlair\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/DataFlairWS\/\" \/>\n<meta property=\"article:published_time\" content=\"2023-05-02T03:30:56+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2023-05-02T11:54:42+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2023\/03\/typescript-interview-questions.webp\" \/>\n\t<meta property=\"og:image:width\" content=\"1200\" \/>\n\t<meta property=\"og:image:height\" content=\"628\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/webp\" \/>\n<meta name=\"author\" content=\"DataFlair Team\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@DataFlairWS\" \/>\n<meta name=\"twitter:site\" content=\"@DataFlairWS\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"DataFlair Team\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"16 minutes\" \/>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"TypeScript Interview Questions - DataFlair","description":"TypeScript has become essential tool for web developers to build complex & scalable applications. Check these TypeScript interview questions.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/data-flair.training\/blogs\/typescript-interview-questions\/","og_locale":"en_US","og_type":"article","og_title":"TypeScript Interview Questions - DataFlair","og_description":"TypeScript has become essential tool for web developers to build complex & scalable applications. Check these TypeScript interview questions.","og_url":"https:\/\/data-flair.training\/blogs\/typescript-interview-questions\/","og_site_name":"DataFlair","article_publisher":"https:\/\/www.facebook.com\/DataFlairWS\/","article_published_time":"2023-05-02T03:30:56+00:00","article_modified_time":"2023-05-02T11:54:42+00:00","og_image":[{"width":1200,"height":628,"url":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2023\/03\/typescript-interview-questions.webp","type":"image\/webp"}],"author":"DataFlair Team","twitter_card":"summary_large_image","twitter_creator":"@DataFlairWS","twitter_site":"@DataFlairWS","twitter_misc":{"Written by":"DataFlair Team","Est. reading time":"16 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/data-flair.training\/blogs\/typescript-interview-questions\/#article","isPartOf":{"@id":"https:\/\/data-flair.training\/blogs\/typescript-interview-questions\/"},"author":{"name":"DataFlair Team","@id":"https:\/\/data-flair.training\/blogs\/#\/schema\/person\/c187795dc82ab948373cca526df7c445"},"headline":"TypeScript Interview Questions","datePublished":"2023-05-02T03:30:56+00:00","dateModified":"2023-05-02T11:54:42+00:00","mainEntityOfPage":{"@id":"https:\/\/data-flair.training\/blogs\/typescript-interview-questions\/"},"wordCount":1881,"commentCount":0,"publisher":{"@id":"https:\/\/data-flair.training\/blogs\/#organization"},"image":{"@id":"https:\/\/data-flair.training\/blogs\/typescript-interview-questions\/#primaryimage"},"thumbnailUrl":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2023\/03\/typescript-interview-questions.webp","keywords":["TypeScript Interview Questions","TypeScript Interview Questions and Answers"],"articleSection":["TypeScript Tutorials"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/data-flair.training\/blogs\/typescript-interview-questions\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/data-flair.training\/blogs\/typescript-interview-questions\/","url":"https:\/\/data-flair.training\/blogs\/typescript-interview-questions\/","name":"TypeScript Interview Questions - DataFlair","isPartOf":{"@id":"https:\/\/data-flair.training\/blogs\/#website"},"primaryImageOfPage":{"@id":"https:\/\/data-flair.training\/blogs\/typescript-interview-questions\/#primaryimage"},"image":{"@id":"https:\/\/data-flair.training\/blogs\/typescript-interview-questions\/#primaryimage"},"thumbnailUrl":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2023\/03\/typescript-interview-questions.webp","datePublished":"2023-05-02T03:30:56+00:00","dateModified":"2023-05-02T11:54:42+00:00","description":"TypeScript has become essential tool for web developers to build complex & scalable applications. Check these TypeScript interview questions.","breadcrumb":{"@id":"https:\/\/data-flair.training\/blogs\/typescript-interview-questions\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/data-flair.training\/blogs\/typescript-interview-questions\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/data-flair.training\/blogs\/typescript-interview-questions\/#primaryimage","url":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2023\/03\/typescript-interview-questions.webp","contentUrl":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2023\/03\/typescript-interview-questions.webp","width":1200,"height":628,"caption":"typescript interview questions"},{"@type":"BreadcrumbList","@id":"https:\/\/data-flair.training\/blogs\/typescript-interview-questions\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Blog Home","item":"https:\/\/data-flair.training\/blogs\/"},{"@type":"ListItem","position":2,"name":"TypeScript Tutorials","item":"https:\/\/data-flair.training\/blogs\/category\/typescript-tutorials\/"},{"@type":"ListItem","position":3,"name":"TypeScript Interview Questions"}]},{"@type":"WebSite","@id":"https:\/\/data-flair.training\/blogs\/#website","url":"https:\/\/data-flair.training\/blogs\/","name":"DataFlair","description":"Learn Today. Lead Tomorrow.","publisher":{"@id":"https:\/\/data-flair.training\/blogs\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/data-flair.training\/blogs\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/data-flair.training\/blogs\/#organization","name":"DataFlair","url":"https:\/\/data-flair.training\/blogs\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/data-flair.training\/blogs\/#\/schema\/logo\/image\/","url":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2016\/07\/Data-Flair.png","contentUrl":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2016\/07\/Data-Flair.png","width":106,"height":48,"caption":"DataFlair"},"image":{"@id":"https:\/\/data-flair.training\/blogs\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/DataFlairWS\/","https:\/\/x.com\/DataFlairWS","https:\/\/www.linkedin.com\/company\/dataflair-web-services-pvt-ltd\/","https:\/\/www.youtube.com\/user\/DataFlairWS"]},{"@type":"Person","@id":"https:\/\/data-flair.training\/blogs\/#\/schema\/person\/c187795dc82ab948373cca526df7c445","name":"DataFlair Team","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/2302ebc438084d2f1f993edc1996a0aae01332e81f3227cba8df0c48ec010ca4?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/2302ebc438084d2f1f993edc1996a0aae01332e81f3227cba8df0c48ec010ca4?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/2302ebc438084d2f1f993edc1996a0aae01332e81f3227cba8df0c48ec010ca4?s=96&d=mm&r=g","caption":"DataFlair Team"},"description":"DataFlair Team provides high-impact content on programming, Java, Python, C++, DSA, AI, ML, data Science, Android, Flutter, MERN, Web Development, and technology. We make complex concepts easy to grasp, helping learners of all levels succeed in their tech careers.","url":"https:\/\/data-flair.training\/blogs\/author\/dfteam6\/"}]}},"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/posts\/112940","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/users\/581"}],"replies":[{"embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/comments?post=112940"}],"version-history":[{"count":7,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/posts\/112940\/revisions"}],"predecessor-version":[{"id":113161,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/posts\/112940\/revisions\/113161"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/media\/113160"}],"wp:attachment":[{"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/media?parent=112940"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/categories?post=112940"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/tags?post=112940"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}