JS Tips

Learn practical tips for working with JavaScript

Using JS to add div elements dynamically

Scenario:- Legacy code thrown at you with new UX design, and you cannot touch the original code. So doing latest UI changes is headache. Solution:- Play with the structure of the html and add latest flexbox or grid CSS to make your life hell easier. How i did re-structuring was appending new parent div, which […]

Posted in Javascript | Tagged | Leave a comment

Console.log trick for debugging

Why need see our debug messages bigger and brighter, simply use the below trick. console.log(‘%c This is my log for debugging’, ‘font-size: 40px; color: green;’); “Striving for excellence motivates you; striving for perfection is demoralizing.”  

Posted in Javascript | Tagged | Leave a comment

Working with prettier in Visual studio code

“Whenever you are confronted with an opponent, conquer them with love.” What is prettier ? In layman terms its an handy tool that will format our code against some set standards, default formatting rules to achieve consistent code style. How to install prettier  in VS Code? Search > Prettier – Code formatter Note:- Incase you have […]

Posted in Javascript | Tagged , | Leave a comment

How to check that javascript object contains the given key?

A wet man does not fear the rain. Issue:-How do I check if an object has a key in JavaScript? Example:- // Sample Object const REMINDER = “REMIND_ME”; reminderObj= { INBOX:`${REMINDER}_INBOX`, USERS:`${REMINDER}_USERS`, GROUPS:`${REMINDER}_GROUPS`, } Problem1: Now we want to check that our object have “INBOX” as key or not? Solution:-  Object.prototype.hasOwnProperty.call(reminderObj,”INBOX”); Note:- We could directly […]

Posted in Javascript | Tagged | Leave a comment