Sometimes we need to explicitly
convert a value to string.
In such cases,
we can use either String()
or
toString()
to convert a non-string value to a string.
Number to String
However,
when we need to convert
null
,
or
undefined
into a string,
we can only use String()
.
Using toString()
in such cases
will give us an error.
We will learn more about the
difference between toString()
and
String()
methods in
toString() vs String() method
lesson in our
Learn JavaScript
course.