🔥Limited Offer: Get 50% OFFon AI & Full Stack Courses🔥
Back to JavaScript Notes
Topic #100

JS toString()

The JavaScript toString() method converts a variable (or a value) to a string.

It is a built-in method for many data types, including numbers, arrays, dates, and objects.

The method is useful for:

  • Converting data to a readable format for display
  • Ensuring type compatibility when a string is required
  • Customizing objects other user interfaces
  • Customizing objects for debugging

JavaScript Array toString()

When used on an array, toString() returns the array elements as a comma separated string.

Example

const fruits = ["Banana", "Orange", "Apple", "Mango"];

let myList = fruits.toString();

JavaScript Date toString()

When used on a date, toString() returns a human-readable date and time string.

Example

const d = new Date();

let text = d.toString();

JavaScript Number toString()

When used on a number, toString() returns the number as a string.

Example

let x = 123;

let text = x.toString();

Convert a number to a string, using base 2 (binary):

Example

let x = 123;

let text = x.toString(2);

JavaScript Function toString()

When used on a function, toString() returns the source code of the function as a string.


JavaScript Object toString()

When used on an object, toString() an object returns "[object Object]".

To provide a meaningful string representation, it can be overridden in the object definition:

Example

let person = {

  firstname: "John",

  lastname: "Doe",

}

let text = person.toString();

Want to go beyond the notes?

Join CodingNow 2.0's JavaScript course — live mentorship, real projects, and 100% placement support.

Enroll Now — Free Demo Available

JS toString() – FAQs

Quick answers about learning JS toString() in JavaScript.

This free note from CodingNow 2.0 explains JS toString() in JavaScript — concept, syntax and worked code examples you can copy, run and revise before interviews.
Yes. Every JavaScript topic on CodingNow 2.0, including JS toString(), is 100% free with no signup required.
With focused practice, most students grasp JS toString() in 1–3 days from these notes; pairing it with CodingNow 2.0's mentor-led course takes you to job-ready depth faster.
Use the code examples in this note, then ask doubts for free on the CodingNow 2.0 Community (/community) — expert instructors answer within 24 hours.
WhatsApp
Call NowEnroll Now