10 Important topic of javascript we should learn
1 . Coding Style
Coding style is very important for a web developer. by seeing someone code we can easily judge how efficient he is. Everyone has their own coding style. So we must be improved our coding style by following this role.
So here we discussed some important roles of coding style :
- Our code must be clean and easier for others to read and understand.
- When we declare a function we should be using a space between parameter
- curly braces is commonly used in javascript projects when we use curly braces we should use a space before curly brace opening.
- When we use for loop and if else condition we must be use space after for/if/else
- We should use a space between argument
- After finished the statement we should use semicolons.
- We should split our long line code
Here is an example of good coding
2 . Values
Javascript provides two categories of values primitive and object . Primitive values are Numbers, Booleans, String, Undefined, Null, and Symbols, All primitive values in JavaScript have a common relation. Primitive values are unchangeable
Here is example
Now we see the same output
3 . Object and Function
We know that javascript is a speacial type of object. A property’s value can be an Object and function. But object and function are not primitive. The javascript function is very popular because the function parameter call an argument. and argument pass parameter by value.UnInitialize function parameter will return undefined.
In the first case, this code will return undefined. And the other code will return “Laptop are available”
4 . expression
In javascript expression is a snippet of code that evaluates to a single value. There is a different type of expression
- Arithmetic expression evaluates to a number and
- Logical expression evaluates to true or false
If we want to see 5 + 5 Javascript will return 10
5 . Cross Browser Testing
Cross-browser testing is very important for every web developer. Cross-browser testing means the website you create works smoothly in all kinds of web browsers. As a web developer, it’s our responsibility that our website works for all browsers properly. there is a different kind of browser.Many people using an older browser that doesn’t support some CSS and javascript.That's why we should testing our website in different browser find the problem and solve this problem for this specific browser
6 . Concat()
This method is used to connect two or more arrays. This method creates a new array without change the existing array
If we want to connect these two array
Const number1= [ 1,2,3,4 ]
Const number2 = [ 5,6,17 ]
Now we can see the output [1,2,3,4,5,6]
7 . fill()
In Javascript fill method used to fills the elements in an array with a static value. By default, the value is 0 when filling start and -1 is the default value when filling end
Here is the result of first console [empty,empty,empty,empty,empty] and second console [ 10,10,10,10,10 ]
8 . Comments
In javascript comments can be used to describe the javascript Code. As a developer, we should explain our code by using comment. comments make the code more readable for all developers. we can also use comments for testing our alternative code. There are a different type of comment single line comment //
And multi-line-comments /* */.
9 . try…catch
Error is a common issue for every developer. There is no developer who can not get a single error. For a single mistake of our code script stop immediately, the server stops his response. But there is a syntax to find and handle our exact error. Using try…catch method we can easily handle our error. If try…catch get any error in our code then it try to stop execution and find the specific error with details. If there is no error catch error is ignored.
Here is the example of try…catch
10 . Arrow functions
In javascript ES6 we are familiar with the arrow function.Arrow function allow making our code simple and shorter function syntax
Now we see the output 12.In arrow function, we are able to remove curly braces and the return statement