Created
January 21, 2010 04:14
-
-
Save NV/282574 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| num = 1; | |
| (function () { | |
| alert(num || 2); // 1, Obviosly | |
| })(); | |
| (function () { | |
| var num = num || 2; | |
| alert(num); // 2! | |
| })(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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