The “try…catch” :

Rasel Hossain
2 min readMay 7, 2021

--

There has to the two main block of try…catch one is try and second is the catch.

The syntax of try and catch :

try {

//code…..

}catch(err){

//error handling

}

The try …catch works like this:

  1. First, the code executed the try block
  2. if there were no errors, then the catch(err) is ignored.
  3. if an error occurs, then the try execution is stopped, then the control flows got to the catch(err) block.

Clean Code :

Our code must be as clean and easy to read as possible.

Here are the some commend to make a code clean:

  1. A space between parameters

function test(x, n) {}

2. No space between function name and parentheses

function test()

3.Curly brace { on the same line, after space

function test() {

4.Space around operators

5 + 10

5.Space between arguments

test(“x” , “y”);

6. else without a line break

if (…) {

} else {

}

Comments :

A comment is just for use to describe how and why the code works. Use comment in a code is a good practice but novice programmers often use them wrongly. In javascript, there have two types of comment one is Single line comment and the other is a Multiline comment.

single-line comment:

// this is the single-line comment

Multiline comment :

/* this is the multiline comment */

Var Declarations and Hoisting :

variables declared using “var” are created before any code is executed in a process known as hoisting. Their initial value is undefined

Block-Level Declarations :

Block-level declarations are the ones that declare variables that are far outside of the given block scope. Block scopes, also known as lexical scopes, are created either inside of a function or inside of a block. Block scoping is how many C-based languages work, and the introduction of block-level declarations in ECMAScript 6 is intended to bring that same flexibility (and uniformity) to JavaScript.

Functions with Default Parameter Values :

In JavaScript, function parameters default to undefined. However, it's often useful to set a different default value. This is where default parameters can help.

function append(value, array = []) {
array.push(value)
return array
}

--

--