What You Have To Know About JavaScript
Data Types Concept
Data types are the most important thing in every programming language. So it is important to know about data types.
Data types are two types.
- Primitive Data Type
- Non-primitive Data Type
Primitive Data Type
There are six primitive data types in JavaScript. This are-
- String
- Number
- BigInt
- Boolean
- Undefined
- Symbol
There also is a null data type, which is seemingly primitive, but indeed is a special case for every Object and any structured type is derived from null by the Prototype Chain.
Non-primitive Data Type
There are three non-primitive data types in JavaScript. This are-
- Object
- Array
- Function
Error Handling
As human beings, none of us are above mistakes. When it comes to programming, we always make mistakes unknowingly. Many times it becomes difficult to find out these mistakes for us. There’s a tool called try…catch in JavaScript which can help us to find our errors. We can find out our errors easily using try…catch.
Here is the try-catch syntax:
The code inside the try block will execute. If there’s any error found then the catch block will execute. Otherwise, the catch block will be ignored.
Coding Style
Coding should be clean and clear as much as possible. Smart and standard coding style helped others to understand code easily. Beautifying is also the art of programming.
Here some rule for beautifying code-
- No space between function name and parentheses
- No space between parentheses and parameter
- Single space between parameters
- Curly braces “{” on the same line after a single space
- Indent code of blocks with 2 or 4 space
- A single space after for/if/while
- A single space around mathematical operators
- A semicolon “;” at line end
- An empty line between logical blocks
- Split every long horizontal line
- A single space around a nested call
Comments
Usually, comments are used to understand the code segment or function which are used for what reason. If we open a project code a long time later it's hard to understand the code. If the project was so big it’s impossible to understand. So, what's the solution? Comments. The programmer uses the comment in the code segment to understand which purpose the code used.
We can comment two different ways.
- Single Line Comment (Start with //)
- Multiline Comment (Lines are blocked with /*…*/)