Skip to content

Instantly share code, notes, and snippets.

@niwatako
Created January 4, 2015 03:02
Show Gist options
  • Save niwatako/69c3d3f51de971076b40 to your computer and use it in GitHub Desktop.
Save niwatako/69c3d3f51de971076b40 to your computer and use it in GitHub Desktop.
JavaScriptと変数宣言
//varを付けずに宣言した変数は、宣言箇所がローカルスコープ内でも勝手にグローバル変数になる
function hoge(){
foo = "(/・ω・)/";
var bar = "(」・ω・)」";
};
hoge();
console.log((typeof foo=="undefined")?undefined:foo); //-> (/・ω・)/
console.log((typeof bar=="undefined")?undefined:bar); //-> undefined
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment