DEV Community

murshedkoli
murshedkoli

Posted on

Advance JavaScript ( new for me)

•JavaScript try-catch

1.The try statement allows to the definition of a block code to be tested for errors while it is run, normally it interrupts the full application and shows errors, if run same code with the Try statement it is not happening.

2.The catch statement allows showing if any error occurs in the try block.

•Error handling
We can give a custom error with the throw statement.

•Coding style
Today I learn the right way to write JavaScript Code. When we add one space and when we add two spaces, likes. After for/if/while we add one space.

•Var Declarations and Hoisting
Write a variable name without value it’s called variable declaration and write a variable with the value it’s called variable initialization.
Ex: var a ;
Var a = 10;
When a JavaScript file run it scan whole page and all variable get in the top of the page, that’s why we can use a variable before it has been declared.

•Cross Browser Testing
Cross-browser testing means testing how to perform our site on all of the web browsers, find the bug and fix it. It happens sometimes code not run the same in all of the web browsers, sometime we should add some CSS code to fix the UI.

•Block Level Declarations
For block level declarations variable should be declare with “let” or “const” , this two keyword make a variable block level. This variable can not be accessible outside the block.

•Function with Default Parameter Values

JavaScript Function has one default value "undefined"
when we do multiplay or add or divided if no value provided then the default value would be undefined.
Working with Unnamed Parameters
Unnamed parameter use for less coding, when function parameter passed without necessarily defining each parameter individually, now passed a parameter with … is means rest of all parameter. We see it in creating Private Route using React Router Dom in React.

there ...rest is the parameter.
see it from here. https://reactrouter.com/web/example/auth-workflow

•The Spread Operator
When All elements to need from an array or object then a spread operator used.
Example: const friends= [nazmul, murshed, hridoy, delowar, nadim, emran];

Const friends2 = […frends];

Console.log(friends2); // [nazmul, murshed, hridoy, delowar, nadim, emran];

Top comments (0)