Home » JavaScript

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

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)





Comments and Discussions

Ad: Are you a blogger? Join our Blogging forum.



Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing » Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© https://www.includehelp.com some rights reserved.