• Node.js Video Tutorials

NodeJS v8.serializer.writeDouble() Method



The NodeJS v8.serializer.writeDouble() method of class v8.serializer is used to write a JavaScript number value to the internal buffer.

The JavaScript number values represent the floating point numbers such as 32, 324.52, or -214.43.

This method is mainly used inside the custom serializer._writeHostObject() that is used to write some kind of host object.

Syntax

Following is the syntax of the NodeJS v8.serializer.writeDouble() method

v8.serializer.writeDouble(value)

Parameters

This method accepts only one parameter.

  • value − A JavaScript number value that will be written to the internal buffer.

Return Value

This method returns undefined instead, it writes a JavaScript number value to the internal buffer.

Example

In the example below, we are trying to write a JavaScript number value that will be written to the internal buffer using NodeJS v8.serializer.writeDouble() method.

const v8 = require('v8');
const serializer = new v8.Serializer();
console.log(serializer.writeDouble(2343.3252));

Output

As we can see in the output below, the writeDouble() method returns undefined instead, it writes the passed value to the internal buffer.

undefined

Example

In the following example, we are trying to write a JavaScript number value to the internal buffer. Then we are releasing the internal buffer to check whether the JavaScript number is written or not.

const v8 = require('v8');
const serializer = new v8.Serializer();
serializer.writeDouble(2343.3252);
console.log(serializer.releaseBuffer());

Output

If we compile and run the above code, the output will be as follows −

<Buffer 52 49 9d 80 a6 4e a2 40>
nodejs_v8_module.htm
Advertisements