Effective approaches in JavaScript 👻

SaravananVijayamuthu
Frontend Weekly
Published in
3 min readJul 27, 2020

🔅 Use { } instead of new Object( )

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

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.

🔅 Reduce global variables

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

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.

🔅 Use strict

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

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

--

--

SaravananVijayamuthu
Frontend Weekly

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