Skip to content

Instantly share code, notes, and snippets.

@wolftatsu
Created January 7, 2014 06:35
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/8295463 to your computer and use it in GitHub Desktop.
Save wolftatsu/8295463 to your computer and use it in GitHub Desktop.
JavaScript 変数宣言時の型を確認する
(function(){
console.log("start!!");
// この時点ではまだ未定義(undefined)
// typeof() で変数の型を確認することができます
var x;
console.log("variable x is " + typeof(x));
console.log("x = " + x);
// やっと型がnumberになる
x = 0;
console.log("variable x is " + typeof(x));
console.log("x = " + x);
// 期待する結果
x = x + 10;
console.log("variable x is " + typeof(x));
console.log("x = " + x);
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment