0
0
Typescriptprogramming~20 mins

What is TypeScript - Practice Questions & Exercises

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
TypeScript Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate
2:00remaining
What is TypeScript mainly used for?

TypeScript is a programming language that is a superset of JavaScript. What is its main purpose?

ATo add static types and catch errors before running the code
BTo style web pages with colors and layouts
CTo replace HTML for building web pages
DTo run JavaScript code faster in the browser
Attempts:
2 left
💡 Hint

Think about what TypeScript adds to JavaScript to help developers.

Predict Output
intermediate
2:00remaining
What is the output of this TypeScript code?

Consider this TypeScript code snippet:

function greet(name: string) {
  return `Hello, ${name.toUpperCase()}!`;
}

console.log(greet("world"));

What will it print?

Typescript
function greet(name: string) {
  return `Hello, ${name.toUpperCase()}!`;
}

console.log(greet("world"));
ATypeError at runtime
BHello, world!
CHello, WORLD!
DSyntaxError during compilation
Attempts:
2 left
💡 Hint

Look at how the toUpperCase() method changes the string.

Predict Output
advanced
2:00remaining
What error does this TypeScript code raise?

Look at this TypeScript code:

let age: number = "30";

What error will the TypeScript compiler show?

Typescript
let age: number = "30";
AType 'string' is not assignable to type 'number'.
BSyntaxError: Unexpected string
CNo error, code runs fine
DReferenceError: age is not defined
Attempts:
2 left
💡 Hint

Check the type declared and the value assigned.

🧠 Conceptual
advanced
2:00remaining
Which feature is unique to TypeScript compared to JavaScript?

Which of these features is only available in TypeScript and not in plain JavaScript?

ALoops to repeat actions
BFunctions to perform calculations
CVariables to store data
DInterfaces to define object shapes
Attempts:
2 left
💡 Hint

Think about features that help describe data structures before running code.

🚀 Application
expert
3:00remaining
What is the value of 'result' after running this TypeScript code?

Analyze this TypeScript code:

type User = { name: string; age: number };

const users: User[] = [
  { name: "Alice", age: 25 },
  { name: "Bob", age: 30 },
  { name: "Carol", age: 35 }
];

const result = users.filter(u => u.age > 28).map(u => u.name).join(", ");

console.log(result);

What will be printed?

Typescript
type User = { name: string; age: number };

const users: User[] = [
  { name: "Alice", age: 25 },
  { name: "Bob", age: 30 },
  { name: "Carol", age: 35 }
];

const result = users.filter(u => u.age > 28).map(u => u.name).join(", ");

console.log(result);
AAlice, Bob, Carol
BBob, Carol
CAlice
DError: Property 'age' does not exist
Attempts:
2 left
💡 Hint

Look at the filter condition and what is extracted after filtering.