×

Index

JavaScript Tutorial

JavaScript Examples

CSS Tutorial

CSS Examples

String() function with example in JavaScript

JavaScript String() function: Here, we are going to learn about the String() function with Example in JavaScript.
Submitted by IncludeHelp, on February 02, 2019

JavaScript String() function

String() function is a predefined global function in JavaScript, it is used to convert an object to the string.

Example

In this example, we are going to convert different object’s values to the string.

<html>
<head>
<title>JavaScipt Example</title>
</head>

<body>
	<script>		
		var a = "10";	
		var b = "10 20";
		var c = "1234 Hello";
		var d = "Hello 1234";
		var e = true;	
		var f = new Date();
		
		//converting values to string using String() function
		document.write("String(a) = " + String(a) + "<br>");
		document.write("String(b) = " + String(b) + "<br>");
		document.write("String(c) = " + String(c) + "<br>");
		document.write("String(d) = " + String(d) + "<br>");
		document.write("String(e) = " + String(e) + "<br>");
		document.write("String(f) = " + String(f) + "<br>");
	</script>
</body>
</html>

Output

String(a) = 10
String(b) = 10 20
String(c) = 1234 Hello
String(d) = Hello 1234
String(e) = true
String(f) = Sat Feb 02 2019 23:03:12 GMT+0530 (India Standard Time)

JavaScript Built-in Functions »




Comments and Discussions!

Load comments ↻





Copyright © 2024 www.includehelp.com. All rights reserved.