Blog 1: JavaScript Related FAQs
-
var keyword in JavaScript: The var is the oldest keyword to declare
a variable in
JavaScript.
Scope: Global scoped or function scoped. 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. -
let keyword in JavaScript: The let keyword is an improved version
of the var keyword.
Scope: block scoped, The scope of a let variable is only block scoped. It can’t be accessible outside the particular block ({block}). -
const keyword in JavaScript: The const keyword has all the
properties that are the same as the let keyword, except the user cannot update it.
Scope: block scoped, 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.
-
Syntax of regular functions:- let x = function
function_name(parameters){
// body of the function
};
Syntax of arrow functions:- let x = (parameters) => {
// body of the function
}; - Unlike regular functions, arrow functions do not have their own this.
- Arguments objects are not available in arrow functions, but are available in regular functions.
Template literals are enclosed by backtick (`) characters instead of double or single
quotes.
Along with having normal strings, template literals can also contain other parts called
placeholders, which are embedded expressions delimited by a dollar sign and curly
braces: ${expression}. The strings and placeholders get passed to a function — either a
default function, or a function you supply. The default function (when you don't supply
your own) just performs string interpolation to do substitution of the placeholders and
then concatenate the parts into a single string.
To supply a function of your own, precede the template literal with a function name; the
result is called a tagged template. In that case, the template literal is passed to your
tag function, where you can then perform whatever operations you want on the different
parts of the template literal.