Effective approaches in JavaScript 👻

SaravananVijayamuthu
Jul 27 · 3 min read
Image for post
Image for post

🔅 Use { } instead of new Object( )

Image for post
Image for post

Similarly, always treat numbers, strings, or booleans as primitive values. Not as objects. Because →

Image for post
Image for post

I don’t use ‘var’. I use ‘let’ and ‘const’

`var` is now the weakest signal available when you define a variable in JavaScript. The variable may or may not be reassigned, and the variable may or may not be used for an entire function.

◾ I use `let` when I need to reassign a variable( like the counter in a loop ). The variable will be used only in the block it’s defined in.

`const` is a signal that the identifier won’t be reassigned. If I don’t need to reassign, `const` is my default choice over `let`. Since I want the usage to be as simple as possible in the Code.


🔅 Use Comments

◾ To increase readability.

◾ To debug errors.

◾ It’s really helpful once you hand over the project to new people.

Image for post
Image for post

🔅 Reduce global variables

◾ It significantly reduces the chance of bad interactions with other applications, widgets, or libraries.

Image for post
Image for post

Downsize apps into smaller segments and use “import” to load whenever required.


🔅 Use === instead of ==

◾ When use == your variable will be converted to match types, whereas === the operator forces a comparison of values and types.

Image for post
Image for post

🔅 Use strict

◾ You can’t use a variable without declaring it.

Image for post
Image for post

Use template strings over the concatenation of strings it feels much easier and readable


If anything is not clear or you want to point out something, please reach me

Like this article? Follow @saravanan.vijayamuthu on Instagram

Frontend Weekly

It's really hard to keep up with all the front-end…

SaravananVijayamuthu

Written by

Ambivert. Webdev. Communicator. Internet guru. Coffee enthusiast. cynophile.

Frontend Weekly

It's really hard to keep up with all the front-end development news out there. Let us help you. We hand-pick interesting articles related to front-end development. You can also subscribe to our weekly newsletter at http://frontendweekly.co

SaravananVijayamuthu

Written by

Ambivert. Webdev. Communicator. Internet guru. Coffee enthusiast. cynophile.

Frontend Weekly

It's really hard to keep up with all the front-end development news out there. Let us help you. We hand-pick interesting articles related to front-end development. You can also subscribe to our weekly newsletter at http://frontendweekly.co

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch

Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore

Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store