JavaScript String toString() Method - JavaScript Tutorial

JavaScript String toString() Method

BLUF: This tutorial on JavaScript String toString() Method provides an in-depth look at JavaScript's core features. It includes practical examples and code snippets to help you master modern JS development.
Key Discovery: JavaScript String toString() Method

Understanding JavaScript String toString() Method is crucial for building dynamic, interactive web applications. Explore the examples below to see it in action.

The toString function in JavaScript retrieves a string that represents the object it is called on. Essentially, this function offers a string depiction of the object and functions similarly to the valueOf method.

Syntax

The syntax representing the toString method is as follows:

Example

object.toString()

Returns

A String representing the object

JavaScript String toString Method Example

Let's explore a few basic illustrations demonstrating the utilization of the toString method.

Example 1

Here, we will print the value of string object.

Example

<script>

var str="Example";

document.writeln(str.toString());

</script>

Output:

Output

Example

Example 2

Let's explore another instance demonstrating how to display the value of a string object.

Example

<script>

var str=new String("Example")

document.writeln(str.toString());

</script>

Output:

Output

Example

Input Required

This code uses input(). Please provide values below:

Logic Practice
Install Logic Practice
Add to home screen for a faster app-like experience