I am afraid many people are going to find my question quite trivial, but I need to ask it.
(As requested by a lot of people, I have edited the code so that you can reproduce it.)
I have a JavaScript global variable defined within a script tag, as shown below:
<!DOCTYPE html>
<html lang="en">
<head>
<!--JQUERY-->
<script type="text/javascript" src="js_test/jquery-1.8.2.min.js" ></script>
<script type="text/javascript">
var store_categories = [];
function init_filtering() {
store_categories.push('data');
alert ("alert1: "+ store_categories);
}
</script>
<script type="text/javascript">$( init_filtering );</script>
</head>
<body>
<script type="text/javascript">
alert ("alert2: "+ store_categories);
</script>
</body>
</html>
When the page is loaded, alert2 appears first with blank value and then alert1 appears showing 'data' as value.
Can anyone please tell me what is happening?
window.store_categories = [];