Skip to content

Instantly share code, notes, and snippets.

@wolftatsu
Last active January 2, 2016 11:18
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 wolftatsu/8295259 to your computer and use it in GitHub Desktop.
Save wolftatsu/8295259 to your computer and use it in GitHub Desktop.
JavaScript 変数の初期化
//条件分岐
var direction = "right";
// 初期化してはじめて、型をnumberとして認識する
var x = 0, y = 0;
switch (direction) {
case "right":
x = x + 10;
break;
case "left":
x = x - 10;
break;
case "up":
y = y - 10;
break;
case "down":
y += 10; // y = y + 10
break;
default;
// 例外処理
break;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment