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.
To convert Javascript int to string, use the toString() method. The toString() method converts the number to a string.
number.toString(base)
The toString() function accepts a single optional parameter base. The base parameter defines the base in which the integer is represented in the string.
The number.toString() function returns a string representing the specified Number object.
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));
1011 string
1011 string
1011.00110101110000101000111101011100001010001111011 string
10011 string
#javascript #developer