Local variables (var i) are used inside functions and cannot be addressed outside that same function.
Member variables can be used in all member functions of the same class (e.g. this.point1 in class Line2P).
Global variables are sometimes unavoidable.
PI, etc. is defined as convenience to be used in input fields in QCAD where values and expressions can be entered. A user may for example enter 2*PI for the distance of a parallel line instead of the usual JavaScript 2*Math.PI. These should be avoided in scripts and are meant for user level input fields.