More Js Concept
Published: 2022-01-14 13:56:01

Scope: 
Scope in JavaScript defines accessibility of variables, objects and functions.
Global Scope:
Variables declared outside of any function become global variables. Global variables can be accessed and modified from any function.
Local Scope:
Variables declared inside any function with var keyword are called local variables. Local variables cannot be accessed or modified outside the function declaration.


Null vs Undefined
Null:
Null is used to represent an intentional absence of value. It represents a variable whose value is undefined. It accepts only one value, which is null. The Null keyword is used to define the Null type in TypeScript, but it is not useful because we can only assign a null value to it.

Example
Variable declared and assigned to null  
var a = null;   
console.log( a );   output: null  
console.log( typeof(a) );   output: object  
Output:




Undefined:
It represents uninitialized variables in TypeScript and JavaScript. It has only one value, which is undefined. The undefined keyword defines the undefined type in TypeScript, but it is not useful because we can only assign an undefined value to it.

Example
Variable declaration without assigning any value to it  
var a;        
console.log(a);  undefined  
console.log(typeof(a));  undefined  
console.log(undeclaredVar);  Uncaught ReferenceError: undeclaredVar is not defined

Closure:
A closure can be defined as a JavaScript feature in which the inner function has access to the outer function variable. In JavaScript, every time a closure is created with the creation of a function.
The closure has three scope chains listed as follows:
Access to its own scope.
Access to the variables of the outer function.
Access to the global variables.

Event Bubbling:
Event bubbling is a way of event propagation in the HTML DOM. It relates to the order in which events are propagated in nested elements.



In bubbling, when an event happens, the handler of the innermost element runs, then the parents, and then the further ancestor elements. In other words, events bubble up or propagate the DOM tree upwards.

Event Delegation:
Event Delegation is basically a pattern to handle events efficiently. Instead of adding an event listener to each and every similar element, we can add an event listener to a parent element and call an event on a particular target using the .target property of the event object.

Prototypal Inheritance:
The Prototypal Inheritance is a feature in javascript used to add methods and properties in objects. It is a method by which an object can inherit the properties and methods of another object. Traditionally, in order to get and set the [[Prototype]] of an object, we use Object.getPrototypeOf and Object.setPrototypeOf. 

API:
The definition or meaning of API is a set of protocols used to create and integrate application software. APIs reside between the web server and application and acts as a middle-man between the two. API allows communication of your products and services with other products without the need for implementation guidelines.

Encapsulation:
Encapsulation is a process of binding the data with the functions acting on that data. It allows us to control the data and validate it.