I'm very used to using web3 = new Web3(web3.currentProvider)
and I saw here that MetaMask sample code is using window.web3 = new Web3(web3.currentProvider)
What's the difference between using and not using the window
keyword?
Ethereum Stack Exchange is a question and answer site for users of Ethereum, the decentralized application platform and smart contract enabled blockchain. It only takes a minute to sign up.
Sign up to join this communityI'm very used to using web3 = new Web3(web3.currentProvider)
and I saw here that MetaMask sample code is using window.web3 = new Web3(web3.currentProvider)
What's the difference between using and not using the window
keyword?
check this question - https://stackoverflow.com/questions/5786851/define-global-variable-in-a-javascript-function
If web3 is not defined as a global variable, but you have "web3 = new Web3(web3.currentProvider)" inside a function - the web3 object will be local for that function only, while with window.web3 it will be globaly accessible