The way of changing variables depends on the type of scope. See how to change for each type of scope: not inherit, inherit and isolated.
Read the tutorial and find out one of the methods of checking whether the element is visible after scrolling with jQuery. Also, find about utility function.
This tutorial provides the method of checking whether the type of the variable is undefined. Read about the differences between undefined and “undefined”.