Var VS Let VS Const in Javascript
The differences between var, let, and const variable declaration in JavaScript include: Variables declared with var and const are scoped to the immediate function body. Variables declared with the var keyword are hoisted. Hoisting means that the variable can be accessed in their enclosing scope even before they are declared. Variables declared with the let keyword are block-scoped, which means the variables will have scope to the immediate enclosing block.
Arrow Function VS Regular Function
In regular function, you have to use return keyword to return any value. If you don’t return anything then the function will return undefined. Arrow functions behave in the same way when returning values. If the arrow function contains one expression, you can omit the curly braces, and then the expression will be implicitly returned. In regular function, Arguments keywords can be used to access the arguments of which passed to function. Arrow functions do not have an arguments binding.
Map VS forEach VS Filter VS Find
Foreach takes a callback function and run that callback function on each element of array one by one. Basically forEach works as a traditional for loop looping over the array and providing you array elements to do operations on them. 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. The provided callback to map modifies the array elements and save them into the new array upon completion that array get returned as the mapped array.
Why use template string?
Template literals provide an easy way to interpolate variables and expressions into strings. It also allow variables in strings. Template literals allow expressions in strings. Subjectively it looks better and is easier to read, especially for multi-line strings or strings containing both ' and " since you don't have to escape those characters any more.