How much data can a global javascript variable store?

To enable the return function using the ajax div, I created these simple functions, and I was wondering how much data the global .js variable can store.

    var dataAfterSearch; //global variable which holds our search results

function goBackAfterSearch() {
    /**
    *   function which displays the previous state
    *
    **/
    $.ajaxSetup ({
        cache: false
    });
    //alert("Previous Search" +dataAfterSearch);
    $('#result').html(dataAfterSearch);
     paginateIt();
}
function setDataAfterSearch(data)
{   
    /**
    * function to set the global dataAfterSearch
    *
    **/
    dataAfterSearch = data;
}

Yours faithfully

+3
source share
4 answers

There are no restrictions, the maximum size depends on the browser / implementation.

You can check the limit by running the script as follows:

var str = "";
var sizeCount = 0;
while( true ) {
   str += "a";
   if( ++sizeCount >= 1048576 ) { // Show an alert for every MB
      alert( str.length );
      sizeCount = 0;
   }
}

I get an error in Chrome about 26 MB.

+12
source

Ya , , 6 java script, , ( JVM ), mozilla IE, , .

+1

, . ( - , AJAX), , .

bytes.com, , .

0

a variable in javascript may contain an object or a string. An object is an unlimited data structure. Lines are limited only by implementation (as Bob said), and should not be an obstacle for you.

0
source

Source: https://habr.com/ru/post/1737202/


All Articles