Blogs

1. What is the difference among var, let and const?

# The main differences between var, let and const are:

1.var is function-scoped while let and const are block-scoped.
2. var variables can be reassigned while let and const variables can not.
3. var variables are declared using the var keyword while let and const variables are declared using the let and const keywords respectively.
4. const variables are immutable while let and var variables are not.

2. What is the difference between arrow function and regular function?

# The Difference Between Regular Functions and Arrow Functions:

1. Syntax

The first and most obvious difference between arrow functions and regular functions is their syntax. Not only do they look different, but arrow functions also provide an implicit return shorthand and allow parenthesis around a single argument to be omitted.

2. Arguments binding

Another difference is the binding of the arguments object. Unlike regular functions, arrow functions don't have their own arguments object. A modern alternative that circumvents this limitation is the usage of rest parameters.

3. Use of this keyword

Unlike regular functions, arrow functions do not have their own this. The value of this inside an arrow function remains the same throughout the lifecycle of the function and is always bound to the value of this in the closest non-arrow parent function.

4. Using new keyword

Regular functions created using function declarations or expressions are constructible and callable. Since regular functions are constructible, they can be called using the new keyword. However, the arrow functions are only callable and not constructible, i.e arrow functions can never be used as constructor functions. Hence, they can never be invoked with the new keyword.

5. No duplicate named parameters

Arrow functions can never have duplicate named parameters, whether in strict or non-strict mode.With arrow functions, duplicate named arguments are always, regardless of strict or non-strict mode, invalid.

3. What is the difference among map, forEach, filter and find?

# The difference among map, forEach, filter and find:

1. The main difference between forEach and filter is that forEach just loop over the array and executes the callback but filter executes the callback and check its return value.
2. Map like filter & foreach takes a callback and run it against every element on the array but whats makes it unique is it generate a new array based on your existing array.
3. Function .find() is also a search function like the previous but they differ in one small detail — this function returns only one match in an array. If in an array is more than one result, the function will return the first that has matched.

4. Why we should use template string?

# We should use Template String in JavaScript because:

Template strings are a powerful feature of modern JavaScript released in ES6. It lets us insert/interpolate variables and expressions into strings without needing to concatenate like in older versions of JavaScript. It allows us to create strings that are complex and contain dynamic elements.Another great thing that comes with template strings are tags. Tags are functions that take a string and the decomposed parts of the string as parameters and are great for converting strings to different entities.