javascript-tutorial / javascript-tutorial/en.javascript.info

Mention endianness and alignment in section ArrayBuffers, binary arrays

Open Beginner friendly
#2,581 1 comment 0 reactions 0 assignees View on GitHub
PR wanted
Dominant language
HTML
Stars
25.5k
Forks
4k
PR merge metrics
No merged PRs in 30d

Description

* Alignment: My browser (Firefox 87.0 on Linux x86_64) doesn't let me create an unaligned Uint16Array. I. e., `new Uint16Array(b, 1, 1)` on a 4-byte array buffer gives `RangeError: attempting to construct out-of-bounds TypedArray on ArrayBuffer`. In the standard that is [22.2.1.5](https://262.ecma-international.org/6.0/#sec-%typedarray%-buffer-byteoffset-length).13a.

* Endianness: Uint16Array is little-endian on my machine. I just learned that this is machine dependent ([https://stackoverflow.com/questions/7869752/javascript-typed-arrays-and-endianness](Stackoverflow)). In contrast, `dataView.getUint16()` is big-endian, unless the second argument is true.

Hope this helps.

Contributor guide

No contributing guide indexed for this repository

Research direction

Find the tutorial section titled “ArrayBuffers, binary arrays” and review the existing explanation around typed arrays and DataView. Add clear notes covering alignment restrictions and the endianness distinction described in the issue, including the relevant behavior for Uint16Array and dataView.getUint16(). Done when readers can understand both caveats from that section.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
documentation
Issue type
Documentation
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
65/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.