Ayesha Sahar
Developer | Designer | Tech Blogger
for the second one you could use string interpolation instead of adding a + "", looks a bit cleaner :D
Nice tips and tricks . Knew almost all of them . But that is because I am working with JS for quite some time. This is really helpful for a beginner.
CONVERT TO NUMBER
let int = +"16";
console.log(int); // Output: 16 console.log(typeof int);
Thanks for sharing, some of them are useful in a few situations.
However I would not advise people to use some of this tricks, especially the hacky conversion ones.
Those would make the code "short", but definitely not "clean".
For clean code, write code using well-known features of the language.
Also I'd rather read a code a few lines longer, than an incomprehensible, or over-smart 1-liner.
Again, thanks for sharing, just giving a different perspective.
I was today years old when I found out about this 🤯:
int = +int; // string to number
Joseph Pham
Software Engineer
extremely useful