Primitive Values and Importance of Standard Coding in JavaScript

Abu Saleh Faysal
3 min readMay 6, 2021

Primitive Values are those values that we can not change. Such as String, Number. For example in JavaScript, if we code like this,

On the other hand, Object and Function are values but they are not primitive. We can manipulate them in our own way.

Now, if you want to check the type of value, you can simply use typeOf(). By using typeOf(), JavaScript will return a number, string, or object.

We talked so much about how to get our desired output and why are we getting it. But, what if we do not get our desired output. Yes, you guessed it correctly, we are going to discuss errors. If you are a programmer or coder, it’s very unlikely that you would not face errors. There are too many ways to handle errors.

One of the very fundamental ways of handling errors is “try…catch”

By this we if the code has no error, it is executed smoothly, but if there is one, then it avoids the execution and going the catch block where the error is caught and we can get detail about that error.

By getting detail about that error, it is much easier to find the solution to that error.

Try…catch is a very logical way to handle the error. However, for developing a project where multiple people work together, we should always maintain clean coding. Clean code always helps to understand the concept clearly and make progress on it.

For example, a piece of code can be written like this.

However, this same piece of code can be written like this as well.

--

--

Abu Saleh Faysal

Software Engineer at Onethread | Front-End Developer | Blockchain Enthusiast | JavaScript | TypeScript | React | Redux