Variable, scope, and memory

When we describe a variable in JavaScript, there is no limit to how much data this variable holds. The maximum is described by the browser's capacity depending on how much data it can hold. Let's take a look the following code:

var abc="xyz";

We can define a variable in JavaScript using the var keyword. We can define the value of a variable immediately or later. A variable that we define outside the boundary of a function is a global variable.

Tip

Creating too many global variables in JavaScript is a very bad approach. The major reason why global variables are discouraged in JavaScript is because in JavaScript, all the code shares a single global namespace, also JavaScript has implied global variables, that is, variables ...

Get Web Developer's Reference Guide now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.