0
0
Typescriptprogramming~20 mins

Number type behavior in Typescript - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Number Type Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2:00remaining
Output of arithmetic with mixed number types
What is the output of this TypeScript code snippet?
Typescript
const a: number = 5;
const b: number = 2.5;
const c = a + b;
console.log(c);
A7
B7.5
CTypeError
DNaN
Attempts:
2 left
💡 Hint
Remember that TypeScript's number type includes both integers and decimals.
Predict Output
intermediate
2:00remaining
Result of dividing by zero
What will this TypeScript code output?
Typescript
const x = 10 / 0;
console.log(x);
AInfinity
BNaN
C0
DThrows an error
Attempts:
2 left
💡 Hint
Think about how JavaScript and TypeScript handle division by zero.
Predict Output
advanced
2:00remaining
Output of bitwise operation on numbers
What is the output of this code?
Typescript
const a = 5; // binary 0101
const b = 3; // binary 0011
const c = a & b;
console.log(c);
A8
B7
C1
DTypeError
Attempts:
2 left
💡 Hint
Bitwise AND compares each bit of the numbers.
Predict Output
advanced
2:00remaining
Behavior of Number.MAX_SAFE_INTEGER + 1
What is the output of this TypeScript code?
Typescript
console.log(Number.MAX_SAFE_INTEGER + 1 === Number.MAX_SAFE_INTEGER + 2);
Aundefined
Bfalse
CThrows an error
Dtrue
Attempts:
2 left
💡 Hint
Consider the precision limits of JavaScript numbers.
Predict Output
expert
2:00remaining
Output of floating point addition precision
What is the output of this code snippet?
Typescript
const a = 0.1 + 0.2;
console.log(a === 0.3);
Afalse
Btrue
CTypeError
DNaN
Attempts:
2 left
💡 Hint
Think about how floating point numbers are stored in computers.