Skip to content

Instantly share code, notes, and snippets.

@cristofersousa
Created March 26, 2017 02:49
Show Gist options
  • Save cristofersousa/ead609f03c55f50b64969aedf1ce1999 to your computer and use it in GitHub Desktop.
Save cristofersousa/ead609f03c55f50b64969aedf1ce1999 to your computer and use it in GitHub Desktop.
scope = "global"; // declara uma variável global mesmo sem var
function checkscope2() {
scope = "local"; // alterando o valor da variável global pela local
myScope = "local"; // adicionando uma nova variável global mesmo dentro da função
return [scope, myScope]; // retornando os dois valores declarados dentro da function
}
checkscope2(); // ["local", "local"]: temos efeitos colaterais aqui, esperavamos **["global, local"]**
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment