DEV Community

Discussion on: JavaScript is almost pythonic

Collapse
 
schnubb profile image
Schnubb

There's a method for that:

const x = 2;
x.toString(); // "2"
Collapse
 
elarcis profile image
Elarcis • Edited

Or as an alternative, String(x), which does exactly the same thing, except if x is null or undefined, then it produces 'null' or 'undefined' instead of throwing an error.