Basic JavaScript Question:
Download Questions PDF

How to convert numbers to strings using JavaScript?

Answer:

We can prepend the number with an empty string in JavaScript

var mystring = ""+myinteger;

//or

var mystring = myinteger.toString();
We can specify a base for the conversion,
var myinteger = 14;
var mystring = myinteger.toString(16);

mystring will be "e".

Download JavaScript Interview Questions And Answers PDF

Previous QuestionNext Question
How to convert a string to a number using JavaScript? How to test for bad numbers using JavaScript?