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.
leta=20{leta=30console.log(a)}console.log(a)
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.
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
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.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.
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.
This is the one category where no other language can beat javascript in how ridiculous it is.
function
declarations get hoistet, butclass
declarations don't.var
is function-scoped, whilelet
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.
Yikes! Don't do that! Blocks
{}
exist for a good reason, and thanks tolet
, you probably won't have to wrap things into functions, specially if you're using strict mode.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.