A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://www.geeksforgeeks.org/javascript-string-tostring-method/ below:

JavaScript String toString() Method - GeeksforGeeks

JavaScript String toString() Method

Last Updated : 11 Jul, 2025

The toString() method in JavaScript converts a string object to a string primitive. It returns a string representing the specified object. This method is automatically called when a string object needs to be defined as a text value or concatenated with another string. The toString() method also converts a number to a string.

Syntax:
string.toString()
Parameters: Return Values:

Example 1: This example shows the basic use of the string.toString() Method in Javascript. 

javascript
// Take string as input and display it
// with the help of string.toString() 
// Method
let a = new String("GfG");
console.log(a.toString()); 

Example 2: Taking a string as input and printing it with the help of a string.toString() method.

javascript
// Taking a string as input and printing it
// with the help of string.toString() method
let a = new String("GeeksforGeeks");
console.log(a.toString());

Example 3: Taking a string as input and printing it with the help of string.toString() method.

javascript
// Taking a string as input and printing it
// with the help of string.toString() method
let a = new String("GFGGFG");

console.log(a.toString());

Example 4: In this example, we are converts the variable number to a string using the toString() method and output the result. The typeof operator confirms the type of our output as "string".

JavaScript
let number = 42;
let result = number.toString();

console.log(result);
console.log(typeof(result));

We have a complete list of Javascript string methods, to check those please go through this Javascript String Complete reference article.

Supported Browsers: 

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4