728x90
SMALL
#JavaScript
#JavaScript / Functions / String() / Function to convert number to string
String()
String() is a function that converts a number to a string.
Grammar
String( object )
object : Enter a number or a variable whose value is a number.
example
The value of variable c is 3, which is the addition of number 1 and number 2.
The value of variable d is 12, which is character 1 plus character 2.
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>JavaScript</title>
<style>
body {
font-family: Consolas;
}
</style>
</head>
<body>
<script>
var a = 1;
var b = 2;
var c = a + b;
var d = String( a ) + String( b );
document.write( '<h1>c : ' + c + '</h1>' );
document.write( '<h1>d : ' + d + '</h1>' );
</script>
</body>
</html>
TIP.
Use the Number() function to convert a string to a number.
728x90
LIST