0
0
Typescriptprogramming~20 mins

Why typed arrays matter in Typescript - Challenge Your Understanding

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Typed Array Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2:00remaining
Output of Typed Array Initialization
What is the output of this TypeScript code snippet using a typed array?
Typescript
const arr = new Uint8Array([10, 20, 300]);
console.log(arr);
AUint8Array(3) [10, 20, 300]
BTypeError: Invalid value in typed array
CUint8Array(3) [10, 20, 44]
DUint8Array(3) [10, 20, 0]
Attempts:
2 left
💡 Hint
Remember that Uint8Array stores values as 8-bit unsigned integers, so values above 255 wrap around.
🧠 Conceptual
intermediate
2:00remaining
Why Use Typed Arrays Instead of Normal Arrays?
Which of the following is the main reason to use typed arrays like Uint16Array over normal JavaScript arrays?
ATyped arrays provide fixed-size, efficient storage of binary data with consistent element types.
BTyped arrays automatically resize when elements are added or removed.
CTyped arrays allow storing any type of data including objects and strings.
DTyped arrays can store negative and positive numbers without limits.
Attempts:
2 left
💡 Hint
Think about performance and memory when working with binary data.
🔧 Debug
advanced
2:00remaining
Debug Typed Array Element Assignment
What error or output will this TypeScript code produce?
Typescript
const buffer = new ArrayBuffer(4);
const view = new Uint16Array(buffer);
view[0] = 65536;
console.log(view[0]);
A65536
B0
CRangeError: Value out of range
Dundefined
Attempts:
2 left
💡 Hint
Consider the size limit of Uint16Array elements and how values are stored.
📝 Syntax
advanced
2:00remaining
Identify Syntax Error in Typed Array Declaration
Which option contains a syntax error when declaring a typed array in TypeScript?
Aconst arr = new Uint8Array{10, 20, 30};
Bconst arr = new Int8Array(5);
Cconst arr = new Uint16Array(new ArrayBuffer(4));
Dconst arr = new Float32Array([1.5, 2.5, 3.5]);
Attempts:
2 left
💡 Hint
Check the brackets used for array initialization.
🚀 Application
expert
3:00remaining
Calculate Sum of Elements in a Typed Array
Given the following TypeScript code, what is the value of sum after execution?
Typescript
const data = new Int8Array([-128, 127, 1, -1]);
let sum = 0;
for (const num of data) {
  sum += num;
}
console.log(sum);
A255
BTypeError: Cannot iterate over Int8Array
C0
D-1
Attempts:
2 left
💡 Hint
Add the numbers carefully considering their signed 8-bit values.