News-Portal

What is the difference between var,let and constant?

Var :The var is the oldest keyword to declare a variable in JavaScript. The scope of the var keyword is the global or function scope. It means variables defined outside the function can be accessed globally, and variables defined inside a particular function can be accessed within the function.

Const :The const keyword has all the properties that are the same as the let keyword, except the user cannot update it. When users declare a const variable, they need to initialize it, otherwise, it returns an error. The user cannot update the const variable once it is declared.

Let: The let keyword is an improved version of the var keyword. The scope of a let variable is only block scoped. It can’t be accessible outside the particular block ({block}).

What is the difference between arrow function and regular function?

this value inside a regular function is dynamic and depends on the invocation. But this inside the arrow function is bound lexically and equals to this of the outer function. arguments object inside the regular functions contains the list of arguments. The arrow function, on the opposite, doesn't define arguments (but you can easily access the arrow function arguments using a rest parameter ...args). If the arrow function has one expression, then the expression is returned implicitly, even without using the return keyword. Last but not least, you can define methods using the arrow function syntax inside classes. Fat arrow methods bind this value to the class instance

What is the difference between map,foreach,filter and find?

Foreach: .forEach() is great we need to execute a function for each individual element in an array.It's returned value is undefined

Map:.map() when we want to transform elements in an array. New array will be created as return value.

Find:.find() When you want to select a single element from an array.

Filter: .filter() when you want to select a subset of multiple elements from an array.It returns array with filtered value