The toString() method in Javascript is used with the number and converts a number to a string. The toString() function is used to return the string representing the specified Number object.

Javascript Int to String

To convert Javascript int to string, use the toString() method. The toString() method converts the number to a string.

Syntax

number.toString(base)

Parameters

The toString() function accepts a single optional parameter base. The base parameter defines the base in which the integer is represented in the string.

Return Value

The number.toString() function returns a string representing the specified Number object.

Example

See the below code.

// app.js

let a = 11;
let b = 11.00;
let c = 11.21;
let d = 19;

let opA = a.toString(2);
let opB = b.toString(2);
let opC = c.toString(2);
let opD = d.toString(2);

console.log(opA, typeof (opA));
console.log(opB, typeof (opB));
console.log(opC, typeof (opC));
console.log(opD, typeof (opD));

Output

1011 string
1011 string
1011.00110101110000101000111101011100001010001111011 string
10011 string

#javascript #developer

JavaScript Int to String: Convert Int to String in JavaScript
2.20 GEEK