Some general things about JavaScript

omar meharab
5 min readMay 6, 2021

Another day, another blog about JavaScript. Let us dive into 10 of the things that I am going to talk about today.

Types of Data in JavaScript

There are different types of data in JavaScript. In total there are 9 types of data. They are:

Null, Undefined, Booleans, Numbers, Stings, Symbols, BigInts, Objects, and Functions.

The funny thing is even though there are 9 types, you can put them in two categories.

01. Primitive Values

These types of values are there when you are coding but you can not actually utilize them in and of themselves. But they will show up when you need them. You will see them in the results or the console.log() of your codes.

Null: This value is given when there is no value or the value is missing,

Undefined: This value is given when the value is not defined or the value is missing

Booleans: They two options ‘True’ and ‘False’. they appear in logical operations.

Numbers: You use them when you do the maths.

Stings: In one word “Text” are strings.

Symbols: They are not common like the others but you can use them to hide details of code implementation.

BigInts: They are new and the most uncommon data type in JavaScript. You will use them for maths when you are calculating a big number. Not just one or two zeros bigger than 100 or 1000 but they are for exponential numbers.

these 9 are the primitive values.

02. Objects and Functions

The second type is Objects and function. They say everything is an Object. If you think about it a bit you will realize it too. But in Javascript lots of values fall in this category.

Objects: Using curly braces you write objects. For example:

let love = {firstName: "Sanjana", lastName: "Afrin", condition: null}

Functions are what make your code come out alive. A simple function can be adding two numbers.

Fun fact, even an array is an object in JavaScript.

03. Expressions

Expression is what you write in math. Say x + y is an expression. It will give you the result according to the values of x and y. After that, it will return one value. This is what expressions are.

Error Handling

Now that we have talked about types of data, let's discuss “Errors”. I love errors (JK). While coding you will get errors here and there. It does not matter if you are getting small errors or big errors. What's important is that you know how to handle them.

04. try…catch

No, you do not need to catch anything literally. But your code will. You can compare the try…catch to be similar to if…else statement. In an, if…else the code tries to do something after a condition is fulfilled in an, if but if it doesn't work, it will go to else. Similarly, the try…catch will try to execute your code in the try part and if it can complete the task then will ignore the catch, else it will go to catch.

try {// write your code here} catch (error) {// handle error here, maybe write a console.log("code did not work properly");}

Coding Best Practices

Let's talk about some not-so-coding errors rather than human errors, after all “To err is human”.

05. Coding Styles

Even though our code is written for the understanding of the computer, that does not mean it should be unreadable to humans. For making your codes more readable and easily understandable for humans you should keep your codes syntactically correct. Follow the below rules to keep it clean and easy to read for others.

a. Space between multiple parameters in a function.

b. Spaces around operators.

c. Correct indentations (Use tab instead of space).

d. Space between arguments.

e. An empty line to separate between logical blocks.

f. Spaces around nested cells.

g. Semicolons at the end of the declarative lines.

06. Commenting on Codes

Sometimes the functions that we create while coding may not be understandable to others who read our code or try to work on it later. So commenting is something that will help you and others understand the codes late on. Remember to keep the comments concise and understandable. Even explaining a function in one line can help you later on. But try to be a bit elaborate. Instead of saying this does this, try to say about input and the expected output. You can comment in single line and multi-line.

// single line comment/*
multi-line comment
*/

Caching, Client & Server Side

Now comes an interesting topic, Caching. Many may have heard about this topic but never really dug deeper. So, let’s learn about it.

What caching is?

Caching is collectively many techniques but the concept is simple. You try to show data as fast as possible to the client by keeping them in several places and instead of generating data every time that data is called, you will show previously stored data. That is in short is caching. If you do not need to show every data after generating because of a request, you can easily bring the time of showing data in the UI or the client. This is increasing the productivity of your application by showing the data faster. You can do this for the data which are unchanging data. For instance, location of and unmoving file or directory or version number, etc.

07. Client-Side Caching

Client caching is keeping the repeatedly called data locally. The data might be a small amount of data but is used continuously. In this case, maybe the images are stored locally, or a few of the contents of a web application are stored in the local place. What this does is, reduces the data cost in the perspective of the network, its utilization, and the processing.

08. Server-Side Caching

for server-side caching, it's a bit different but the concept is similar to showing the previously saved data. Now for the server-side, think of a commonly made request, so the server creates a copy for the return of that request. Now, whenever that request is made server checks if the copy the server has cached is the right answer to the call, if it matches then the copy is sent to the client-side, if not then the request is processed normally.

Cross Browser & Testing

You may only use chrome but that does not mean everyone else is the same. Some will use Mozilla and some will use Edge( :p ). So it is important for developers to test their codes in major browsers and optimizing them that way.

09. What is cross-browser testing?

Cross-browser testing is basically the testing for finding out if the web application or website which you have created is compatible with most of the famous web browsers. As a developer, this is one of your responsibilities.

10. Why cross-browser issues occur?

Now, why do issues occur across different browsers you may ask. There is more than one reason. One reason might be that the browser itself has bugs or features that are implemented differently. Another reason might be one browser is using the latest technology but another browser is just getting around to use that feature etc.

So, these were today's 10 things that I wanted to share with everyone. Hope it was worth your time to read it. See you tomorrow.

--

--

omar meharab

React web developer. Love to learn and love to love