DEV Community

Discussion on: 🚀 Productivity Tips 🚀 for every Javascript Programmer 💻

Collapse
 
darkwiiplayer profile image
𒎏Wii 🏳️‍⚧️

1. Async nature of javascript

That's more of a downside, really. Javascripts Async-Model has been the source of much headache and only recently with async/await it seems like it's reached a level where most programmers are comfortable with it.

2. Interpreted instead of Compiled

This applies to both PHP and Python too, as well as a whole lot of other scripting languages. And it's not even an advantage in the first place; it's a trade-off. Interpreted javascript will never be as fast as well-written C code, and even JIT-Compilers tend to only beat idiomatic C code in very special cases.

3. Supports Promises and Closures and many more.

Promises are not really a language-feature; they could easily be implemented as a library on top of any language that supports some of objects and uses callbacks for asynchronous code.

As for Closures, javascript sadly stores values separately for each closure, so a whole bunch of techniques that use closures with shared state doesn't work.


Understand Scoping of Variables

This is the one category where no other language can beat javascript in how ridiculous it is. function declarations get hoistet, but class declarations don't. var is function-scoped, while let is block-scoped. <script> scripts share a scope across an HTML document, but <script type="module"> scripts have their own scope.

Once you understand all the implications of these differences, they become mostly noise, but for someone learning the language, that's unnecessarily complicated.


Use IIEF Whenever Possible

Yikes! Don't do that! Blocks {} exist for a good reason, and thanks to let, you probably won't have to wrap things into functions, specially if you're using strict mode.

let a = 20
{
   let a = 30
   console.log(a)
}
console.log(a)
Enter fullscreen mode Exit fullscreen mode

Use Promises Instead of Callback Only Approach

Better yet: use async/await. Unlike callbacks, promises are way over-engineered and way too complicated. They can do a lot for you, but they can also do a lot to ruin your day. Even if you think you've understand how they work in detail, the next programmer maintaining your code might not.