10 Things I Learned as a JavaScript Noob Part-2

Md Rana Mahmud
4 min readNov 4, 2020
  1. Checking data type in JavaScript

When you’re writing your JavaScript all values might look similar to the 101 Dalmatian. But behold all that’s not the case here. You can check your value type using JavaScript keyword typeof operator. You can write it two ways typeof(operand) or committing the parentheses typeof operand. Few examples are below:

2. try catch in JavaScript

When we write and run programming often you’ll encounter errors. There are three type of errors we’ll encounter, 1. Compile time error, 2. Runtime Error and 3. Logical error. If we can use our programming language and tools properly we can eliminate and handle these two types of errors.

try…catch is a mechanism in programming language which’ll help you two handle a situation where you might encounter a runtime error. You’ve to remember two things try and catch. After try inside {} we write our code. When there will be any error like file not found, image loading failed the code inside the catch will run. The codes inside the {} up to the error free line. If you’ve any code after the error then it won’t work.

3. coding styles

The way we write our code impacts its readability. We should write our code in a readable and clean way. In the simplest term coding style means how many whitespace you use after braces, how you indent your lines, how you name your variables. There are several popular style guides like Google JavaScript Style Guide, Airbnb JavaScript Style Guide you can follow to make your code more readable and clean.

4. comment in JavaScript

comment is something we run in the code file which doesn’t do anything programming task. In JavaScript we can write comment using // before any line to make it single line comment. For multiline comment we can use /*...*/ . Putting all the lines that we want to be commented between /* and */.

5. arrow function

In JavaScript suppose you have written a function and that function will be only used once. For this kind of situations you can make your code concise using arrow function. For writing arrow function we don’t need to use the function keyword. We type our parameters of function before => and the code inside the function after the => . If you’ve one parameter we can omit the (), if we’ve only one line inside the function we can omit the {}. But for more than one parameter we’ve to use the (). For more than one line in function we’ve to use {}.

6. Cross Browser Testing

Cross browser testing is making sure that your website works on various types of browsers and devices people use. Cross browser testing is necessary because all devices don’t have the same display resolution, browsers might not implement the same web feature same way, they might have bugs. Before testing you should ensure that functionality are working and your code don't have any bug. Then you can go for testing in stable browsers system, like Firefox, safari, chrome, ie/edge, on mobile devices. If you found something not working you fix it then test again. You’ll repeat this cycle until a considerable amount of features are working fine.

7. Functions with Default Parameter Values

When we write function there might be a situation we might think that a parameter will take a predefined value. In such situations we can use default parameter. Default parameter is a value which we write during the declaration of the function unless not supplied during function call will use default value. In the following code the second sumDefault function declaration we declared a default parameter b = 10. So that when we call the function sumDeafult(15) it takes value of b from the default parameter value b = 10, resulting sum 25.

8. JavaScript Event Loop

JavaScript is a single threaded language, but we might think that it is a multithreaded language. The default JavaScript engine V8 in many browsers is single threaded. The JavaScript engine communicates with browser API which works in the background and provides multithreading capability. Event loop is in the simplest term JavaScript engine has one stack of current tasks and another cue for tasks waiting to be done. The event loop checks if there are any pending tasks in the queue and the stack are empty or not. When the stack is empty it takes the task from the queue and places in the stack. Then JavaScript stack. You should be careful about handling tasks so that your browser doesn’t freeze.

9. Caching

Caching is the way of storing already calculated value in memory or disk so that when needed subsequence time it’ll save time using precalculated value. Suppose your client has logged in to your website you can store login credentials in the browser's cache which’ll save time for checking again about the login. You might have a JavaScript script which you can cache for saving bandwidth. There are 3 types of caching, client side, server side and hybrid caching.

10. Expressions

JavaScript code lines that results in a value you can consider as expressions. Suppose you ask JavaScript what is the value of 6 + 7 it'll reply at 13. Expression are JavaScript code that’ll evaluate to a value.

--

--

Md Rana Mahmud

Sr. Data Scientist, Statistician, and Software Engineer. Loves programming and data science.