4 ms·
You'd be relying on undefined behavior by the ECMAScript spec, but sure. Whether it works is implementation dependent, and you'd have no grounds for complaint i
by scarmig 9y ago
You'd be relying on undefined behavior by the ECMAScript spec, but sure. Whether it works is implementation dependent, and you'd have no grounds for complaint if it changed at any time.
Playing around with it in Chrome 65.0.*...
const buffer = new ArrayBuffer(12);
const uint8s = new Uint8Array(buffer);
const floats = new Float32Array(buffer);
floats[0] = NaN, floats[1] = NaN; //127.192.0.0, 127.192.0.0, 0.0.0.0
uint8s[0] = 104, uint8s[1] = 105; //127.192.104.105, 127.192.0.0, 0.0.0.0
floats[2] = floats[0] + floats[1]; //127.192.104.105, 127.192.0.0, 127.192.104.105
console.log(String.fromCharCode(uint8s[8]) + String.fromCharCode(uint8s[9]));