Variable Accessibility in JavaScript

Variable Accessibility in JavaScript

Variable accessibility means how many ways to access the the variable. Its depends on scope of the variable. In javascript there are two types of scope.

1. local scope

2. global scope

JavaScript has function scope: Each function creates a new scope.

Scope determines the accessibility (visibility) of these variables. Variables defined inside a function are not accessible (visible) from outside the function.

 	var x = 10; 	
	function myFunction() {     	
		var name = "xyz"; 	
	} 

Here in example name has the local scope for this function. We can not access it outside of this function but x has global scope because we can access x inside the function and outside of it.

Local variables are created when a function starts, and deleted when the function is completed.

In JavaScript, objects and functions are also variables.

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