0
0
Typescriptprogramming~20 mins

Why TypeScript over JavaScript - Challenge Your Understanding

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!
Predict Output
intermediate
2:00remaining
What is the output of this TypeScript code with type annotations?
Consider this TypeScript code snippet. What will it output when compiled and run?
Typescript
function greet(name: string) {
  return `Hello, ${name.toUpperCase()}!`;
}
console.log(greet("world"));
AHello, world!
BHello, WORLD!
CTypeError at runtime
DCompilation error due to type mismatch
Attempts:
2 left
💡 Hint
Look at how the string method toUpperCase() is used on a typed parameter.
🧠 Conceptual
intermediate
1:30remaining
Why does TypeScript help catch errors earlier than JavaScript?
Which of these best explains why TypeScript can catch errors before running the code?
ABecause TypeScript runs code faster than JavaScript engines.
BBecause TypeScript uses a different syntax that JavaScript engines ignore.
CBecause TypeScript checks types during compilation, preventing type errors before runtime.
DBecause TypeScript automatically fixes all bugs in the code.
Attempts:
2 left
💡 Hint
Think about what happens before the program runs.
🔧 Debug
advanced
2:00remaining
What error does this TypeScript code produce?
Look at this TypeScript code. What error will the compiler show?
Typescript
function add(a: number, b: number): number {
  return a + b;
}

const result = add(5, "10");
console.log(result);
AType error: Argument of type 'string' is not assignable to parameter of type 'number'.
BSyntax error: Missing semicolon
CRuntime error: Cannot add number and string
DNo error, outputs 15
Attempts:
2 left
💡 Hint
Check the types of arguments passed to the function.
🚀 Application
advanced
1:30remaining
How does TypeScript improve code maintainability in large projects?
Which option best describes how TypeScript helps maintain large codebases?
ABy removing the need for any testing in the project.
BBy automatically generating documentation for all functions.
CBy running code faster in browsers than JavaScript.
DBy enforcing explicit types, it makes code easier to understand and refactor safely.
Attempts:
2 left
💡 Hint
Think about how clear types help developers.
Predict Output
expert
2:30remaining
What is the output of this TypeScript code using interfaces and optional properties?
Analyze this TypeScript code and select the correct output.
Typescript
interface User {
  name: string;
  age?: number;
}

function describe(user: User) {
  return `Name: ${user.name}, Age: ${user.age ?? 'unknown'}`;
}

console.log(describe({ name: 'Alice' }));
AName: Alice, Age: unknown
BName: Alice, Age: undefined
CName: Alice, Age: 0
DCompilation error: Missing age property
Attempts:
2 left
💡 Hint
Look at how the optional age property is handled with the nullish coalescing operator.