11 Useful Modern JavaScript Tips

Krina Sardhara
DhiWise
Published in
3 min readMar 7, 2022

--

source: https://www.jstips.co

In our day-to-day coding life, we frequently used numbers to string conversion, check keys in the object it exits or not, conditionally manipulate object data, filter falsy value in the array, etc.

Here I come up with some amazing tips which are my personal favorite ❤️ ️and very useful to make my code shorter and clean.

  1. Conditionally add properties💡 in the object
tip1

2. Check if a property exists in an object or not

tip2

3. Object destructing with dynamic key

4. Loop over an object to access both key and value

5. Prevent throwing an error 🐞 when accessing any key which does not exist in the object using optional chaining (?.)

Alert ⚠️: optional chaining used when you are not sure their property exits or not in data. If you are sure that keys must be coming in data and if there does not come, that time is good to throw an error instead prevent them.

6. Check falsy🌵 values in an array

7. Remove duplicate value in the array

8. Check value is an array type

9. String to Number and Number to String conversion using ‘ + ’ operator 🤩

10. Conditionally assign other values when value is null and undefined using nullish coalescing (??) Operator

Confuse 😕 with OR (||) Operator ??

OR operator used when you want conditionally assign other value if the value is not truthy (0,’ ’, null, undefined, false, NaN)

11. Boolean conversion using the !! operator

Thank you for reading !! . I hope these tips also became your favorite ❤️ :)

--

--