Skip to content

Instantly share code, notes, and snippets.

@gurucharanmk
Last active April 22, 2016 13:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gurucharanmk/e6c1bb820129ca5328687ae17de0e22e to your computer and use it in GitHub Desktop.
Save gurucharanmk/e6c1bb820129ca5328687ae17de0e22e to your computer and use it in GitHub Desktop.
function checkVar() {
var validate = 1; //Make it 0 to execute else block
if(validate) {
var varName = "test"; //comment this line to confirm exception
console.log(varName);
}
else{
console.log(varName); //varName is accessible with value undefined
}
console.log(varName); // varName is accessible and defined if validate = 1, varName is accessible but undefined if validate = 0
}
checkVar();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment