Notes on JavaScript data types, Error handling, es6 block binding, function parameter

Muhammad Ahasanur Rahman
2 min readMay 7, 2021
JS notes

JavaScript has two types mainly. Primitive types (Undefined, Null, Booleans, Numbers, Strings, Symbols, BigInteger ) & Object and function types (Objects, functions). While using this types one may have to handle errors in the JavaScript code. To handle errors JavaScript uses syntax like this which allows handling errors.

The try catch syntax can only handle run time error.

Can’t handle parse time error using try catch syntax

We can throw our own errors in code.

To stay away from errors in es6 we should keep some knowledge about block binding. In a short term you can say block binding is limiting one’s area in a place. For ‘var’ block binding will be like.

Here in line 4 ‘name’ value is undefined but in line14 ‘name’ value is printed because of hoisting. Hoisting is the default behavior of JavaScript of moving all declarations to the top of the current scope. In this mechanism variable and function declarations (not initialization) are put into the memory during the code compile time. Here ‘var’ declarations are treated as if it is in the top of the function scope in line 2 of code. As line 4 is compiled before so we get here value undefined. but in line 14 output will be printed and outside of function we will ge a reference error for ‘name’ variable. Try code for ‘checkBinding(false)’.

But in let and const bindings are not accessible before their declarations. To describe this temporal dead zone terms is used usually.

JavaScript’s function has ability parameter destructuring. Let’s see

We can call a function with a variable number of arguments. Then function can hold all arguments in a array like object ‘arguments’. Let’s see

We can use arrow functions with rest parameters in JavaScript.

I have noted some important things about some of these topics. To know more you can follow MDN documentation or any other source from the internet. The more you read, the more will be clear to you about these topics. Happy learning.

--

--