+ 1
How to access count?
I've a variable named count in store.js set to 0. I want to access it index.js and then log its value. How do I do it?
6 Réponses
+ 2
Then store.js is unknown to your browser.
You have to link a script to HTML page in order to run it. If you don't link it then it won't run and if it won't run variables or functions won't be created.
+ 3
A variable that in in global scope should be accessible from any file.
store.js:
var count = 0;
index.js:
console.log(count);
but you can also do module.exports from store.js and then import it in your index file.
+ 2
Sajid
Did you link your index.js before store.js? Then it will be of course undefined.
0
🔫 Rick Grimes But I'm getting a error saying count is not defined 😥. Why is this happening!!!!
0
🔫 Rick Grimes I didnt link store.js. I only linked index.js
0
🔫 Rick Grimes thanks a lot. I've been stucked here for days. Now I understand why I was getting these stupid errors😡