Jump to content

why are these still global variables?

Recommended Posts

It's my understanding that we need to run this line of code at the beginning of the script (see link) so that the GamePiece variables are global and thus allowing the updateGameArea() function to use them.

If i remove this code the updateGameArea() still runs those objects as though they're global. Surely they're local to the startGame() function by removing this first line of code?

var redGamePiece, blueGamePiece, yellowGamePiece;


Share this post

Link to post
Share on other sites

If you declare the function variables without 'var' the variable becomes automatically global, with var it is local to the function only.

Edited by dsonesuk

Share this post

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Create New...