Which of the following is an example of a good global variable?

Prepare for the CodeHS Animation and Games Test. Study with flashcards and multiple choice questions. Each question is equipped with helpful hints and detailed explanations to boost your confidence. Ace your exam!

A good global variable is one that is relevant and necessary for multiple parts of a program, allowing for easier management and access throughout the code. The ball in the game serves as an excellent example of a global variable because it is a central object that likely needs to be accessed and modified by various functions across the game for tasks such as movement, collision detection, and rendering. Storing the ball as a global variable ensures that all parts of the game can consistently reference and manipulate the ball's state without having to pass it around explicitly as a parameter in every function.

In contrast, a for loop counter is typically confined to the scope of the loop and does not need to be accessed outside of it, making it inappropriate as a global variable. The parameter in a callback function generally exists only within the context of that particular call and therefore would not benefit from being global. Lastly, a color variable intended for use within a single function does not require global status, as it is not shared across multiple functions, thus lacking the broader applicability that defines a good global variable.

Subscribe

Get the latest from Examzify

You can unsubscribe at any time. Read our privacy policy