In JavaScript, you can convert an integer to a string using the toString()
method or by using string interpolation.
In this example,
num
and assign it a value of 42
.toString()
method to convert the integer num
to a string and store the result in the variable strNum
.toString()
method converts the integer to its string representation.// Convert Integer to String using toString() Method
let num = 42;
let strNum = num.toString();
console.log(`String representation of integer: ${strNum}`);
String representation of integer: 42
In this example,
negativeNum
with a value of -10
.negativeNum
to a string and store the result in the variable strNegativeNum
.// Convert Negative Integer to String using String Interpolation
let negativeNum = -10;
let strNegativeNum = `String representation of negative integer: ${negativeNum}`;
console.log(strNegativeNum);
String representation of negative integer: -10
In this tutorial, we learned How to Convert Integer to String in JavaScript language with well detailed examples.