Advertisement
Beginner JavaScript, ArrayBuffer, TypedArrays & Binary Data

Name a few common TypedArray types and their byte sizes.

Short answer

Int8Array uses 1 byte per element, Int16Array uses 2, Float64Array uses 8. JS also has Uint8Array, Uint16Array, Int32Array, Uint32Array, Float32Array, and BigInt64Array/BigUint64Array for 64-bit integers.

Save JavaScript mock interview
Advertisement
AModel answer
Int8Array uses 1 byte per element, Int16Array uses 2, Float64Array uses 8. JS also has Uint8Array, Uint16Array, Int32Array, Uint32Array, Float32Array, and BigInt64Array/BigUint64Array for 64-bit integers.
new Int8Array(1).BYTES_PER_ELEMENT;   // 1
new Int16Array(1).BYTES_PER_ELEMENT;  // 2
new Float64Array(1).BYTES_PER_ELEMENT; // 8
Real-world example
Choosing Uint8Array vs Float64Array matters a lot for memory usage on large binary datasets.
Likely follow-ups
  • What happens if you assign a value outside a TypedArray's range?
Related topics