Essential javascript insights

Samairasama
4 min readMay 6, 2021

There are some javascript insights such as coding style,comment,some ES6 block bindings,try-catch error handling and some other topics which is important to know for a programmer.these have been discussed below:

Codding style: Beautiful and clean code is like a beautiful picture on canvas. to make the code prettier and readable we have to keep it clean and tidy. clean code also represents how cleaner your thought process is.it also helps to make the code understandable for other people.it becomes easily readable. there are some style guides to make our code cleaner and tidier and also readable. these are JSLint, JSHint, ESLint. As a beginner, we can just follow some basic coding style rules. some of the important and easy points are given below:

1.We should give a space between parameters.

Example:

Function sumTwoNumber(a, b)

2.we should not give space between the function name and parentheses between the parentheses and the parameter.

3.we can avoid using curly braces if the line is short.

4.we should use indentation properly.

5.long horizontal lines are boring to read. so we should split the long lines. backticks are allowed us to split a line.

6.we should use semicolons after the end of the line.it helps to understand the finishing point of a line.

7.we should nesting in many deep levels.

Comment: Comments are used to explain the code and make it more readable to a reader.it s basically makes the reader understand what the coder tried to do. the comment is a sign of a good developer. good comment allows us to maintain the code well. there are two types of comments. single-line comment and multi-line comment.

I.single line comment: single-line comment start by ‘ // ’.any text between this are will not be executed in javascript.

Example:

//declaring variable

const c = 5;

const b = 4;

//sum of two number

const sum = c+b;

Ii.multi line comment: multi-line comment starts with /* and end with */.any text inside this will not execute.

Cross-browser testing: Cross-browser testing means testing an application in multiple browsers and making sure that the application works consistently and as intended without any dependencies. some times some applications don't work in one browser but work fine in another browser. Cross-browser is important to enhance efficiency and user experience. there are some automation tools such as BrowserStack,CrossBrowserTesting.com etc which are used for cross-browser testing.

Function with default parameter: if initialized default is passed or no value is passed as parameters inside a function den it's called function with default parameters. if no value is passed den it will return undefined. It’s often used to set different default values.

Syntax: function name(defaultvalue1,…….,defaultvalueN){}

Spread Operator: it takes a group of values such as all the values from an array and tries to spread them into multiple values.it is used when all the element from an array or object needs to be included on a list. It passed all the elements as arguments.

Syntax: newFunction(…iterableObject)

Block-level function:block-level function are those functions that are declared inside a block. the function will not be executable outside the block.it will be undefined if the function is being called. because the function is no longer exists outside the block. block-level functions are hosted to the top of the block in which they are defined.it throws a syntax error in es5 but works absolutely fine in es6.block level functions are similar to let function expression. the function definitions are removed once the execution closed out of the block in which it is defined.

Example:

if(true){

function blockLevel(){

//…

}

blockLevel();

}

here blockLevel() is a block-level function.it will only executable inside the if block.

Arrow function: there is another simple and shortest syntax for creating functions. It's called the arrow function. In order to convert a regular function into an arrow function firstly, we need to remove the function keyword. instead of this everything remain the same, we just have to convert the equal sign into an arrow sign.it does not have any argument.

Example:

const sayHello = (name) => {

return name;

}

Block binding: Variables are more formally known as binding. when we declare a variable we bind a value inside a scope.ES6 offer some block bindings when we declare variable using var/let/const keyword.

Block-level declaration : Block-level declarations are those which are declared inside a block and it will not act as a global variable and will not be accessible outside the specific block that they were declared. there are two types of block-level declarations. we can declare the variable inside the function or inside of a block.

Try-catch:Error handling refers to the response and recovery procedures from error conditions present in a software application.there are many ways to handle error.one of them is using try catch block inside the code.the try statement let us test a block of code for errors.the catch statement catch the error.so an error inside the try block does not kill the script.we can get which type of error is the code getting.the try-catch block only handles runtime errors.

Hope you have enjoyed reading this article and found this article helpful.if you have enjoyed this then follow me on LinkedIn.

--

--