Differences between let, var and const
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.The const
keyword follows the same rules as the let keyword. The only difference
with const is that const is used to define only constant values in
JavaScript programs.
Difference between regular functions and arrow functions
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.
Usage of template literals
Template literals are literals delimited with backtick (`) characters,
allowing for multi-line strings, for string interpolation with
embedded expressions, and for special constructs called tagged
templates. Template literals are sometimes informally called template
strings, because they are used most commonly for string interpolation
(to create strings by doing substitution of placeholders). However, a
tagged template literal may not result in a string; it can be used
with a custom tag function to perform whatever operations you want on
the different parts of the template literal. It provides an easy way
to create multiline strings and perform string interpolation.
Usage of map, filter, foreach, find functions
- The map() method creates a new array populated with the results of calling a provided function on every element in the calling array.
- The filter() method creates a shallow copy of a portion of a given array, filtered down to just the elements from the given array that pass the test implemented by the provided function.
- The forEach() method executes a provided function once for each array element.
- The find() method returns the first element in the provided array that satisfies the provided testing function. If no values satisfy the testing function, undefined is returned.