Welcome to my blog

Var: Var Before the advent of ES6, var declarations ruled. There are issues associated with variables declared with var, though. That is why it was necessary for new ways to declare variables to emerge. First, let's get to understand var more before we discuss those issues.

Scope: Scope essentially means where these variables are available for use. var declarations are globally scoped or function/locally scoped. The scope is global when a var variable is declared outside a function. This means that any variable that is declared with var outside a function block is available for use in the whole window. var is function scoped when it is declared within a function. This means that it is available and can be accessed only within that function.

Hoisting: Hoisting is a JavaScript mechanism where variables and function declarations are moved to the top of their scope before code execution. This means that if we do this

Let is a block scope: The let keyword should be used in situations where you want to declare a variable that should be restricted to the block in which it is restricted. Also, variables declared with the let keyword cannot be updated or re-declared. Here is an example of how to use let to declare variables in JavaScript

Hoisting: Hoisting of let Variables declared with the let keyword are not subject to hoisting. This means you cannot use a variable unless it is declared and initialized.

Const: 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.

const Declarations are Block Scoped: The scoping principles of const are the same as that of the let keyword. Like let, the variables declared with the const keyword will also have scope restricted to the block in which they are declared.

Some important pointers for const include: const declares a variable with a constant value. Use the const keyword if the variable that you are declaring should not be allowed to be reassigned in the future.

Regular function: Inside of a regular JavaScript function, this value (aka the execution context) is dynamic. The dynamic context means that the value of this depends on how the function is invoked. In JavaScript, there are 4 ways you can invoke a regular function. During a simple invocation the value of this equals to the global object (or undefined if the function runs in strict mode):

2 Arrow function: The behavior of this inside of an arrow function differs considerably from the regular function's this behavior. The arrow function doesn't define its own execution context. No matter how or where being executed, this value inside of an arrow function always equals this value from the outer function. In other words, the arrow function resolves this lexically. In the following example, myMethod() is an outer function of callback() arrow function:

Handling strings is one of the most essentials jobs for software development. In JavaScript, there is special syntax for it — template strings (also called template literals). It’s okay if you have never used the template strings syntax, since there are alternative ways to do the same operations. But if you’re serious about JavaScript, mastering this syntax sugar can make your code shorter and better.

TWriting Multi-line Strings Directly: The simplest usage of the template literal is to write a multi-line string directly: