Open this example in the interactive library
Source code
const bytes = Uint8Array.of(254, 255);
console.log(new DataView(bytes.buffer).getInt16(0, true));
Sample output
-2

Read a signed integer with explicit endianness in JavaScript.
Open this example in the interactive library
const bytes = Uint8Array.of(254, 255);
console.log(new DataView(bytes.buffer).getInt16(0, true));
-2