Add missing var statements, braces and semicolons

A few var statements were missing in the code examples, so variables/function might leak into the global scope.

I also added semicolons and missing braces – I know that using semicolons might be a decision of "style", but some examples used them while others were lacking them. Better to be consistent here, as people will blindly copy & paste the code snippets.