courses.reviews logo
I launched a free website to help you find the best courses with reviews & discounts.
Up to date
Published
2 min read

Trevor I. Lasn

Staff Software Engineer, Engineering Manager

Float16Array in JavaScript

Understanding the new 16-bit floating point array in JavaScript

Float16Array is a new type of array in JavaScript that stores 16-bit (2-byte) floating point numbers. It joins the existing family of TypedArrays like Int8Array, Uint8Array, Float32Array, and Float64Array

If you’ve never used TypedArrays before, think of them as specialized arrays that can only contain specific types of numbers.

Unlike regular JavaScript arrays that can mix strings, objects, and numbers, TypedArrays are fixed-size, memory-efficient arrays dedicated to numeric data.

Here’s how you’d create and use a Float16Array

JavaScript
// Create a Float16Array with 4 elements
const myArray = new Float16Array(4);
myArray[0] = 1.5;
myArray[1] = 42.0;
myArray[2] = 0.333;
myArray[3] = -27.5;
console.log(myArray); // Float16Array [1.5, 42, 0.3330078125, -27.5]

Notice something interesting with the third value? 0.333 became 0.3330078125. This happens because 16-bit floating point numbers have limited precision compared to JavaScript’s standard 64-bit numbers.

You might wonder: “We already have Float32Array and Float64Array, so why do we need a 16-bit version?”

The answer comes down to three things: memory, performance, and compatibility.

TypedArrayElement TypeBytes Per ElementDescriptionValue RangePrecision
Float16Array16-bit float216-bit IEEE floating point±65,504~3 decimal digits
Float32Array32-bit float432-bit IEEE floating point±3.4×10^38~7 decimal digits
Float64Array64-bit float864-bit IEEE floating point±1.8×10^308~15 decimal digits

A Float16Array uses half the memory of a Float32Array. If you’re working with large datasets, this can make a significant difference.

For applications processing millions of values, this memory saving can be crucial. In certain contexts, especially with GPU-accelerated computing, 16-bit floats can be processed more efficiently than 32-bit or 64-bit numbers. Newer GPUs often have specialized hardware for handling 16-bit floating point math, making operations potentially faster.

References


Found this article helpful? You might enjoy my free newsletter. I share dev tips and insights to help you grow your coding skills and advance your tech career.

Interested in supporting this blog in exchange for a shoutout? Get in touch.


Liked this post?

Check out these related articles that might be useful for you. They cover similar topics and provide additional insights.

Javascript
6 min read

AggregateError in JavaScript

Handle multiple errors at once

Sep 2, 2024
Read article
Javascript
3 min read

JavaScript's ??= Operator: Default Values Made Simple

A guide to using ??= in JavaScript to handle null and undefined values elegantly

Nov 5, 2024
Read article
Javascript
4 min read

Understanding Bitwise Shifts in JavaScript: << and >>

A practical guide to left and right shift operators in JavaScript

Nov 12, 2024
Read article
Javascript
7 min read

WeakRefs in JavaScript: Explained In Simple Terms

Understanding how WeakRef helps manage memory in JavaScript

Jan 7, 2025
Read article
Javascript
4 min read

JavaScript Import Attributes (ES2025)

Understanding the new import attributes syntax and why we can't rely on file extensions alone

Nov 10, 2024
Read article
Javascript
4 min read

Intl.DurationFormat: Format Time Durations with Locale Support

Stop writing manual duration formatting code. Instead, leverage the new powerful Intl.DateTimeFormat API for internationalized time displays

Mar 13, 2025
Read article
Javascript
4 min read

Embrace Intermediate Variables and Early Returns in JavaScript

Early returns and intermediate variables make your code easier to reason about

Aug 30, 2024
Read article
Javascript
4 min read

Error.isError(): A Better Way to Check Error Types in JavaScript

Why the new Error.isError() method solves important cross-realm issues and provides more reliable error identification than instanceof

May 9, 2025
Read article
Javascript
9 min read

Exploring JavaScript Symbols

Deep dive into JavaScript Symbols - what they are, why they matter, and how to use them effectively

Nov 15, 2024
Read article

This article was originally published on https://www.trevorlasn.com/blog/float16array-javascript. It was written by a human and polished using grammar tools for clarity.