All quizzesEasy
TypeScript Fundamentals — Series 2
Preview — 3 of 10 questions
javascript
enum Direction {
Up = "UP",
Down = "DOWN",
}
console.log(Direction.Up);A0
B"UP"
C"Up"
Dundefined
javascript
let point: [number, number] = [10, 20];
point = [10, 20, 30];ACompiles fine — tuples can have extra elements as long as the first ones match
BCompiles fine, but point[2] is undefined at runtime
CCompile-time error — a tuple type has a fixed length matching its declared elements, so a third element isn't allowed
DRuntime error: "too many array elements"
javascript
function greet(name: string, times: number): string {
return name.repeat(times);
}
greet("Hi", "3");ACompile-time error — "3" is a string, which isn't assignable to the declared parameter type number
BCompiles fine — TypeScript automatically coerces "3" to the number 3
CCompiles fine because function parameter types are only checked at runtime
DCompile-time error, but only because greet was called with the wrong number of arguments
Sign up free to play
Answer all 10 questions (7 more), see explanations for every answer, and track your score.