Skip to content

Instantly share code, notes, and snippets.

@NV
Created January 21, 2010 04:14
Show Gist options
  • Select an option

  • Save NV/282574 to your computer and use it in GitHub Desktop.

Select an option

Save NV/282574 to your computer and use it in GitHub Desktop.
num = 1;
(function () {
alert(num || 2); // 1, Obviosly
})();
(function () {
var num = num || 2;
alert(num); // 2!
})();
num = 1
def func():
print(num || 2)
func() # 1
def func2():
num = num or 2
print(num)
func2() # UnboundLocalError: local variable 'num' referenced before assignment
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment