toString() - Convert numbers to string

PHOTO EMBED

Wed Jan 08 2020 19:00:00 GMT+0000 (Coordinated Universal Time)

Saved by @goblindoom95 #javascript #numbers #jsfunctions

var x = 123;

//OPTION 1
var y = x.toString();           

//OPTION 2
var y = (123).toString();        

//OPTION 3
var y = (100 + 23).toString();   

// value of y is 123 in all 3 cases.
content_copyCOPY

line 1: assign a number value to the variable x line 4: convert value of x to string using the toString() method and store it in a new variable y. line 6: convert value of x to string using the toString() directly on numbers line 10: convert value of x to string using the toString() directly on mathematical expressions. NOTE: it is not necessary to store the value of toString() in a new variable.