UnboundLocalError on local variable when reassigned after first use

Python treats variables in functions differently depending on whether you assign values to them from inside or outside the function. If a variable is assigned within a function, it is treated by default as a local variable. Therefore, when you uncomment the line, you are trying to reference the local variable c before any value … Read more

Is the underscore prefix for property and method names merely a convention?

That’s only a convention. The Javascript language does not give any special meaning to identifiers starting with underscore characters. That said, it’s quite a useful convention for a language that doesn’t support encapsulation out of the box. Although there is no way to prevent someone from abusing your classes’ implementations, at least it does clarify … Read more

Python 3: UnboundLocalError: local variable referenced before assignment [duplicate]

This is because, even though Var1 exists, you’re also using an assignment statement on the name Var1 inside of the function (Var1 -= 1 at the bottom line). Naturally, this creates a variable inside the function’s scope called Var1 (truthfully, a -= or += will only update (reassign) an existing variable, but for reasons unknown … Read more

What underlies this JavaScript idiom: var self = this?

See this article on alistapart.com. (Ed: The article has been updated since originally linked) self is being used to maintain a reference to the original this even as the context is changing. It’s a technique often used in event handlers (especially in closures). Edit: Note that using self is now discouraged as window.self exists and … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)