Sunday, November 17, 2024
Google search engine
HomeLanguagesJavascriptJavaScript arrayBuffer.byteLength Property

JavaScript arrayBuffer.byteLength Property

The Javascript arrayBuffer.byteLength is a property in JavaScript that gives the length of an arrayBuffer in bytes. 

Syntax:

ArrayBuffer.byteLength

Parameters: It does not accept any parameter because arrayBuffer.byteLength is a property, not a function.

Return Value: It returns the length of an arrayBuffer in bytes.

JavaScript code to show the working of the arrayBuffer.byteLength property:

Example: This is a basic example showing the usage of arrayBuffer.byteLength property.

javascript




// Creation of arrayBuffer of size 5 bytes
let A = new ArrayBuffer(5);
 
// Using property byteLength
let bytes1 = A.byteLength;
 
// Printing the lengths of the ArrayBuffer
console.log(bytes1);


Output

5

Errors and Exceptions:

If the length of arrayBuffer is given in fractions, it returns length in the whole number and when the length is given in the form of string then it returns a length of zero (0). 

Example 1: In this example, we will pass the length of arrayBuffer in fractions.

javascript




// Creation of arrayBuffer of sizes 5.6
let A = new ArrayBuffer(5.6);
 
// Using property byteLength
let bytes1 = A.byteLength;
 
// Printing the length of the ArrayBuffer
console.log(bytes1);


Output

5

Example 2: In this example, we will pass the length of arrayBuffer in string format.

javascript




// Creation of arrayBuffers of sizes "a" bytes
let A = new ArrayBuffer("a");
 
// Using property byteLength
let bytes1 = A.byteLength;
 
// Printing the length of the ArrayBuffer
console.log(bytes1);


Output

0

Whether you’re preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, neveropen Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we’ve already empowered, and we’re here to do the same for you. Don’t miss out – check it out now!

RELATED ARTICLES

Most Popular

Recent Comments