DEV Community

Discussion on: JavaScript Best Practices for Beginners

Collapse
 
syedafrozpasha profile image
Syed Afroz Pasha • Edited

Firstly, Thank you for taking the time to read my article.

  • I agree with you we shouldn't use global variables at all. But there might be some scenarios where we might require to use global variables depending on projects.

  • Well, different developers use different styles for writing a piece of code. In my case, I would prefer to check falsy values by using NOT operator (!), which is very much cleaner and does the job.

  • Agree with you, it is preferred to use optional chaining operator (?.) with the coalescing operator (?? or ||). Again it depends on the developer, how he/she want to use it. I would do something like this.

const county = user?.address?.country || 'Default Value';
Enter fullscreen mode Exit fullscreen mode
  • Wow, that's an interesting solution 👍

Let's not forgot that this article is for beginners who have just started learning JavaScript. What I have cover in this article is just the tip of the iceberg 😉

Lastly, Thanks for the tip, I will make sure to add code snippets instead of images in the future.

Cheers! 👍