Variables in JS
The main difference between const and let is const can not change its value after declaration while let can do. But let is a local variable, means can not use its value outside of the function if it is declared inside of the function.
Functions in JS
There is two way to define a function.
Regular Function and Arrow Function
An arrow function is pretty handy to use and makes the code more readable and easy to maintain as it gets longer with time.
Simple steps to follow up to use the arrow function:
- Remove the ‘function’ keyword.
- Then add the ‘=>’ after ().
Still, both can use the parentheses to pass parameters and if you have one parameter just omit the parentheses.
If you are writing a function as follows, the way you are called it is a little bit differ from as usual.
Here I use a function inside of the function. The reason to use the function inside a function is to access both local and global variable.
So that we can not get the value as a variable. So you can declare a variable that holds a function and call that variable as a function.
Destructing Method for Objects
Hope all know what is an object. If not here is the object.
The person is the object name. And the name, age, occupation are properties of an object. Usually, we call them key and value.
It seems like a JSON. But the object is not exactly to same as that.
And we can access those properties like this:
If have a big amount of variables to declare we use destruct method.
And if you want to put the name into a new variable called developerName, here you can do it.