“Expert JavaScript ”

1 . Discuss about Error handling

  1. in error handling using Four keyword
  2. try
  3. catch
  4. finally
  5. throw

2. why use error handling?

Then if we create large apps suppose 1000 line code in the run time has found anyone line error we can not see our output for that reason using error handling. if we use try catch it’s ignore the error code and display the output.

declaration of try..catch

try{

code….

}

catch(){

}

catch is a function it work is before find execution error handle

try work where error have a possibility that’s place

Example:

try{

alert(“Hello everyone”);

alert(“Bye Bye”);

}

catch(){

alert(“Inside catch block”)

}

if try block code is ok catch block does not work but in try block have identify error then catch is work and ignore the error and the output

3. try..catch only work for run time error

JavaScript engine first read the code and then run

2. try catch use finally block

try{

alert(“Hello everyone”);

alert(“Bye Bye”);

}

catch(err){

alert(“Inside catch block”)

}

finally{

alert(“God bless you”);

}

1. throw statement

throw statement create custom error.

The throw operator generates an error.

throw <error object>

  1. There may be no catch section or no finally, so shorter constructor and try..catch are also valid.

3 .Coding Style

coding style is the actually the art of programming

  1. Curly Braces
  2. line lentgh
  3. Indents :
  4. semicolon
  5. nesting lavel
  6. function placement
  7. style guide
  8. automated linters

this is very important for the coding style

4 .JavaScript comments

// this is single-line comment

/*…….*/ multiline comment

those use the visual studio code or VSCode use

ctrl +slash

5. ES6/ECMAScript

example :

var x = 1;
let y = 1;

if (true) {
var x = 2;
let y = 2;
}

console.log(x);
expected output: 2

console.log(y);
expected output: 1

6.Hoisting

  • Hoisting Bangla meaning Uttolon or Uporer dike tola
Hoisting example image

7. Block-level declaration, Block-Binding

  1. Inside of a function
  2. Inside of a block (indicated by the { and } characters)

var/let/const

  1. it al time can use

2. var is a function scope inside the function area it can call

example:

if(true){

var myVariable=“This is var”;

}

console.log(myVariable);

let

  1. if have possibility to change the variable name then use the let l

example :

let patient=20;

patient=40;

if(true){

let letVariable=“this is let”;

console.log(letVariable);

}

2. let is block scope it only work in block area not other

const

1 .if variable value do not have to chance to change in next that time use the

const.

2. const fix no change

example:

const country=“Bangladesh”;

console.log(country);

8 .Function default parameter

example:

default parameter image

9 .Spread Operator

  1. The spread operator allows an expression to be expanded in places where multiple arguments (for function calls) or multiple elements (for array literals) are expected.

2. using spread operator do concatenate work easily

example:

Spread operator image

10. Arrow function

arrow function

in arrow function minimum if there are two parameter use ()

*Multiline arrow function

multiline arrow function