Indexed Collections and Typed Arrays
Indexed collections address elements by numeric position. An Array stores general JavaScript values; a typed array views a sequence of numeric elements in a binary buffer using a particular element representation.
An ordinary list holds values. A binary view tells you how to interpret bytes in shared storage.
First separate the storage from the view
An uploaded image, an audio sample and a network packet eventually involve binary data. A normal JavaScript array is useful for a list of article records, but does not describe the byte layout of a file. ArrayBuffer supplies byte storage; a typed array supplies an indexed view into it. DataView supplies explicit typed reads and writes at byte offsets.
4 bytes: [0, 0, 0, 0]The buffer has four bytes. bytes.length is 4 because Uint8Array uses one byte per element. words.length is 2 because Uint16Array uses two bytes per element. Both views refer to the same storage; they are not independent copies. Typed array element count and buffer byte count are different measurements.
The DataView write stores a two-byte integer with littleEndian=true, so the least significant byte is written first. Its hexadecimal value 0x1234 becomes bytes 0x34 and 0x12, which are decimal 52 and 18. Read it back with the same byte order. A mismatched byte order reads different data. Direct multi-byte typed-array views use the platform's byte order; use DataView when a file or protocol specifies an order.
A view can share or copy
subarray(start, end) creates another view over the same storage. A write through that view is visible through the original view. slice(start, end) creates a copy of the selected elements in new storage. Replacing the word 'view' with 'copy' in your mental model creates bugs when an image edit unexpectedly changes another component's data.
These examples use a fixed-size buffer. Do not assume all modern buffers are permanently fixed: resizable and transferable buffers have additional rules. Learn those against the specific environment before adopting them; they are not needed for this packet.
Numeric representation changes the result
A Uint8Array element represents an unsigned 8-bit integer. Assigning 257 stores 1 after conversion to that representation. This is not the same as range validation, and ordinary unsigned conversion is not the same as the clamping behavior of Uint8ClampedArray. A typed array cannot replace a form validator. Typed arrays do not supply ordinary array resizing methods such as push.
Predict and inspect
Before running, predict whether changing part[0] will change bytes[1]. Then change the DataView write to big endian by passing false, and inspect the byte order. Change only one thing at a time. In the independent task, the endianness is part of the input contract and must be explicit.
Change the inputs and see the result
This lab executes the displayed operations with real JavaScript values. Change one input, predict which output changes, then compare the result.