What is closure in JavaScript

Closure in JavaScript

A closure is the combination of a function and the lexical environment within which that function was declared.

A closure is an inner function that has access to the outer enclosing function's variable scope chain.

A closuer can access its own variables, outer functions variables and global variables.

We can create a closure by adding a function inside another function.

 function show() {   
var name = 'My Name'; // name is a local variable created by show   

function displayName() { 
// displayName() is the inner function, a closure     
alert(name); // use variable declared in the parent function       



How To Use Server-Sent Events …

How To Use Server-Sent Events in Node.js to Build a Realtime App. Server-Sent Events (SSE) is a technology based on HTTP. On the client-side, it provides an API called EventSource (part of the HTML5 standard) that allows us to connect to the server a …

read more

How To Use node-cron to Run Sc …

How To Use node-cron to Run Scheduled Jobs in Node.js . cron provides a way to repeat a task at a specific time interval. There may be repetitive tasks such as logging and performing backups that need to occur on a daily or weekly basis.One method fo …

read more