On passing by reference and hoisting in javascript

Okay so javascript passes by value when your dealing with primitive types like integers and string values. Unless we are talking about a case where you are dealing with closures in which case the variables declared outside of the closure are actually managed by refernece. (See Closures for a more indepth look)

But you can pass objects by ref
http://snook.ca/archives/javascript/javascript_pass

Generally speaking, It can in itself lead to pitfalls in particular with the reference to the “this” inside your function. Depending on how you declare and use a function, the “this” ref can be different. So short answer… you can do it if you absolutely need to and are familiar with all the potential roadblocks with it however, (opinion)Its more often than not worth the trouble.

Example is when you pass a function as a parameter such that

(a lot of it has to do with variable scope in js defaulting to function scope as opposed to block scope)

This talks about variable hoisting and scoping issues with using reference to “this”
http://bonsaiden.github.com/JavaScript-Garden/#function.this