Javascript discussion with an example
Tags: javascript
Published: 2021-06-13 19:42:52

1.var

var is a javascript variable declaration keyword, var is a global or function scope variable. you can declare a variable in a function then you cannot access the variable this function outside but you can declare globally a variable then you access this variable anywhere. you can update and re-declare a variable.

example:
![Example Image](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/cpeqz56unn220cz0437b.JPG)

2.let

let is a variable declaration keyword, but it is different from the var keyword. let is block scope variable. you can declare a variable with let in a block then you can access this variable in the block but you cannot access this variable outside in the block. you can update the variable but you cannot re-declare this variable.

example:
![Example Image](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/rsochruaonqd7m5ecfed.JPG)

3.const

const is a variable declaration keyword, but it is almost the same as the let variable. const is a block scope variable. you can declare a variable with const in a block then you can access this variable in the block but you cannot access this variable outside in the block. You can't update and re-declare this variable.

example:
![Example Image](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ko0zu9zdprknxctzfyo5.JPG)

4.Arrow function

arrow function is a function and difference between a traditional function expression. you declare an arrow function then store this function in a variable and you use the arrow function directly as a call back function. an arrow function doesn’t have the name. it is an anonymous function. you can’t provide any parameter then must give a parenthesis bracket and you provide only one parameter then you can’t use parenthesis bracket but you provide two or more parameter then must use parenthesis bracket.

example:
![Example Image](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/fxgnsd3jmv4kci1pbx66.JPG)

5.Spread Operator

The spread operator is used to add items to arrays, combine arrays or objects, and spread an array out into a function argument. if you used instead of the array concat() method.

example:
![Example Image](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/szhd2uhw3c0fitdj815q.JPG)

6.Rest parameter

The rest parameter is using in function last arguments. if you used the rest parameter in function parameters then you can provide an indefinite parameter.

example:
![Example Image](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/g2gdh7cvby1d1xdebkhz.JPG)

7.typeof

The typeof is using to check data type. if you declare a variable then check your variable data type.

example:
![Example Image](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/eq1xpny1aqriz83dpy4a.JPG)

8.Default parameter

the default parameter is using for a function parameter, you used the function default parameter then you call the function but don’t provide the parameter then the function work with the default parameter but you can provide the parameter of function then the function work with this parameter.

example:
![Example Image](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/zalm8t3tib2btxm9pa7l.JPG)

9.try catch

the try catch is using for error handle, you used the try catch block, try block is used for code error then any error your code, error pass the catch block and catch block is using for handle errors.

example:
![Example Image](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/1c60713jghh6xma31zog.JPG)

10.arguments

The arguments is an array-like object, it is used for the access function parameters.

example:
![Example Image](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/uuh4n5fl2vmuevid92vj.JPG)