Ten things I didn’t know about Javascript Before

I have been reading, learning and researching about Javascript for quite some time. A lot I have learnt. Surely I have lot to learn more. Recently, I found ten important things I didn’t know before about javascript. Today I am going to talk about them!

**In Javascript

this above style is marked as a bad comment style.It is encouraged to use the below style for commenting.

**Though there is no “must follow” rules for javascript in styling still a generalised style of each language helps different coders to read,modify,develop the same code easily. And for helping coders to stay in conventional style , there are tools named ‘Linters’ . There are some popular linters available.ESLint is probably the newest one. Most linters are integrated with many popular editors: just enable the plugin in the editor and configure the style.

**Those function having ‘try..catch ’ clause and also using ‘setTimeout’ function — this setTimeout function must be applied to whole function not just in ‘try’ clause.Just look at the examples below

The above example will not work properly.catch will run before the try clause .And there will be no error as try clause hasn’t even run yet!Now look at the below example-

This will work properly. As the setTimeout function is applied to the main function not just in ‘try’.

**Let’s think code within a function excuted properly , but this execution is not fullfilling all your requirements such as one information is missing , or output value is negative which was not supposed to be negative! What to do?

Here comes ‘throw’ operator! It is used to generate coder’s own error.Look at the example give below-

Here , coder has created an error message when she is not getting username. So , in spite of smooth excution , it will return an error set by coder for providing incomplete data.

**try..catch works like this or that . You can’t have both! But that’s not all! There is another code clause ‘finally’! It will run for sure no matter if the code ran smoothly or caught an error. Loot at the example below-

** Outside the try..catch code clause what if there is an fatal error? The user never wants to see the site to crash . It creates such irritation! And even if there is an unwanted, unexpected error ,they want to be informed about it. They don’t like to feel clueless. For this purpose , Globalcatch is used.

** Surprisingly I got to know in Javascript there are total nine types of values present. These nine values have been classified into three sections mainly- primitive values, object and function. Within the primitive values we got — null,undefined,numbers, boolean,strings and symbols.

**‘Date’,‘Array’ — these are not identified as unique data type in Javascript. These all are under the ‘Object’ data type.

**Let’s be clear about ‘unidentified’ and ‘null’ data types.

Unidentified is unintentional missing values such as declaring a variable without initializing it with a value will have data type and value ‘undefined’.Where null is intentional missing values.

**The values of undefined and null is equivalent but the type is different.What I am trying to say would be clear enough through the code below-

So, finally I think I could give you some new and useful information about Javascript . Javascript is so vast , I am still learning , processing what I have learnt.

A Learner, an avid reader