Javascript encyclopedia

try, catch

JavaScript Try Catch Exception Example. The try statement lets you test a block of code for errors. The catch statement lets you handle the error.

}catch (err){// handle Error err
// FInal result

In the try section, where you write your code, like API request. If you get any error, you handle the error from the catch section. Actually, this is a major part of try-catch. Try cath to help you to write crash-free code.

Spread Operator is another magic from es6 if want to merge array object. Just use three-dot before the array/object

now console the newer. Boom, here your new complete new array.

The function is a magic box in programming. If your need to done same work to many time, like sum calculation. Then you can use the function.

retrun a + b; 
const result = sum(2,5)
const result2 = sum(7,7)

Now you can use your sum function how many times you want but don’t write new code for sum.

Function Parameter parameter makes your function dynamic. Each time you make a new calculation with a newer number by the same function. But your function not yet makes any problem. Because of the parameter. When dealers a function with a parameter, they have to pass the parameter's value when using it.

// write your code with perameter

Return is important significant for function, in function, after complete your task, you will get some value, and you have passed this value to the user. For this reason, you have to use return. In return mean your function job is done, and the user will get the result.

const result = a + b;return result;
// now nothing will execute


in es6 const is very important for the developer sometimes happens already declared variable, unfortunately, you declare again. and start shadowing in a program. It’s too annoying. For solving this problem, es6 introduces const if you declare any variable with const. Next time, you can’t dealer any variable in the same name. It will show an error.


sometimes your need to reassign a new value in the variable. But if you use const, you can’t reassign a new value in the variable. For this solution. es6 give let keyword. If you use the let keyword, then how many times you can modify your variable.

Keep learning…

A full-stack developer and learner.