Why Communication Skills Is An Important Skill For Developers
May 30, 2022Help! I’ve Had To SSH Into A Linux Box (Part 2)
June 13, 2022
As a full-stack developer I often look for ways to continuously improve my code, whether it be performance, optimization, readability or generally making my life easier. JavaScript has so many language features that allow you to experiment with so many different concept considering it’s used in both front-end and back-end frameworks.
It is a dynamically typed language, which means variables are assigned a type at runtime based on their value. Much like other dynamically typed languages, this opens up a great deal of possibilities to what you can do with data manipulation in your code.
This article highlight some of these language features which fall into 3 categories:
Make your life easier (W)
Unique array records (W)
A Set is JavaScript object that is used to create a record of unique values. This is useful if you want filter out duplicates (whatever the type) in an array object.
Quick type conversions (W)
As mentioned above, JS is a dynamically typed language which makes type conversion, although strange, but very easy and kind of wonderful
Array/Object manipulation (W)
Having to work with objects of data, not just in JSÂ but other languages. Often times to find yourself having to loop of these objects, nest some of those loops with some conditions. While some of these object manipulation tricks are popular and familiar in JS, here’s a few unpopular ones I’ve found to be very nifty.
Spread Syntax
Beautiful (B)
ES2020 language features (B)
BigInt
A special JS numeric type that provides support for integers of arbitrary length.
Nullish Coallesce
Allows us to truly and correctly check for nullish values (null
, undefined
) instead of falsey values.
Optional chaining
Optional chaining allows us to access deeply nested object properties without worrying if the properties exist or not. This is useful especially if you’re not sure what the data looks like or it does not have a consistent structure.
globalThis
A this
object that always refers to the global object, no matter where you are in you code scope.
Promise.allSettled()
Unlike Promise.all()
which resolves only when all promises passed to it resolve else rejects with the first rejected promise error, Promise.allSettled
always get resolved with an array having info about all the promises passed to it, whether resolved or rejected.
Dynamic Import
Used to import JS files dynamically as JS modules in your code
Some/many of this ES2020 may not be compatible with older browser/JS environments. Enter BabelJS. BabelJS is a JS compiler that is mainly used to convert ECMAScript 2015+ code into a backwards compatible version of JavaScript in current and older browsers or environments. Here’s an example of babel at work (from babel docs)
Weird (L)
The Weird Stuff (L)
As mention, JS a is dynamically typed language. So this opens up a room for a lot error when it comes types and their interpretation.
Hers’s a few honorable mentions that make JS what many would define as annoying but I just find hilarious and very quirky.
You can find more of these on denysdovhan/wtfjs.
Conclusion
I have not been heavily involved in front-end development lately and so many thing mentioned above may not be entirely correct/accurate anymore. If you do spot something that may have changed or forgot to mention, please highlight it in a comment below.