Skip to content

Instantly share code, notes, and snippets.

@aitskovi
Last active December 10, 2015 19:59
Show Gist options
  • Save aitskovi/4485474 to your computer and use it in GitHub Desktop.
Save aitskovi/4485474 to your computer and use it in GitHub Desktop.
varscope
function invalid(a) {
var inner = function() {
console.log(a);
var a = '2';
console.log(a);
}
inner();
}
function valid(b) {
var inner = function() {
console.log(b);
var a = '2';
console.log(a);
}
inner();
}
/**
* invalid('1') ->
* 'undefined'
* '2'
*
* valid('1') ->
* '1'
* '2'
*
* Is this expected behaviour or a bug?
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment