0
0
Typescriptprogramming~20 mins

What survives compilation to JavaScript in Typescript - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
TypeScript Compilation Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2:00remaining
What is the output after TypeScript compiles this code?
Consider this TypeScript code snippet. What will be the output when the compiled JavaScript runs?
Typescript
const num: number = 5;
function greet(name: string): string {
  return `Hello, ${name}!`;
}
console.log(greet('Alice') + ' Number is ' + num);
AHello, Alice! Number is undefined
BCompilation error due to type annotations
CHello, Alice! Number is 5
DHello, Alice! Number is num
Attempts:
2 left
💡 Hint
Type annotations are removed during compilation but variable values remain.
Predict Output
intermediate
2:00remaining
Which part of this TypeScript code is NOT present in the compiled JavaScript?
Look at this TypeScript code. After compilation, which part will NOT appear in the JavaScript output?
Typescript
interface Person {
  name: string;
  age: number;
}

const user: Person = { name: 'Bob', age: 30 };
console.log(user.name);
AThe interface Person
BThe object user
CThe console.log statement
DThe property user.name
Attempts:
2 left
💡 Hint
Interfaces are only for type checking and do not exist at runtime.
Predict Output
advanced
2:00remaining
What will this compiled JavaScript output?
Given this TypeScript code, what will the compiled JavaScript output when run?
Typescript
enum Color {
  Red,
  Green,
  Blue
}

console.log(Color.Green);
A"Green"
B1
Cundefined
DCompilation error
Attempts:
2 left
💡 Hint
Enums are compiled into objects with numeric values starting at 0.
Predict Output
advanced
2:00remaining
What error does this compiled JavaScript produce?
This TypeScript code uses a type assertion. What happens when the compiled JavaScript runs?
Typescript
const someValue: unknown = "hello";
const strLength: number = (someValue as string).length;
console.log(strLength);
Aundefined
BTypeError at runtime
CCompilation error
D5
Attempts:
2 left
💡 Hint
Type assertions do not exist in JavaScript and do not affect runtime behavior.
Predict Output
expert
2:00remaining
What is the output of this TypeScript code after compilation and execution?
This TypeScript code uses a generic function and a type parameter. What will the compiled JavaScript output when run?
Typescript
function identity<T>(arg: T): T {
  return arg;
}

console.log(identity<number>(42));
A42
Bundefined
CCompilation error
DNaN
Attempts:
2 left
💡 Hint
Generics are removed during compilation and do not affect runtime.