How can I determine whether a variable is a string or something else in JavaScript?
![Check if a variable is a string in JavaScript](https://cdn-ak-scissors.b.st-hatena.com/image/square/98d6f053a97a87156775f60757c60865d0f2c47d/height=288;version=1;width=512/https%3A%2F%2Fcdn.sstatic.net%2FSites%2Fstackoverflow%2FImg%2Fapple-touch-icon%402.png%3Fv%3D73d79a89bded)
How can I determine whether a variable is a string or something else in JavaScript?
jQuery や underscore.js では isFunction とか isArray とかの型判定関数的なものがあります。 え?ライブラリ使わないとJavaScriptはろくに型すら判別できないの? 半分YESで半分NO。 そもそも typeof とはなんぞやというお話し。 よく typeof と instanceof の違いについて、 「typeof は型の文字列表現を返して、instanceof は型から派生されたかどうかを返すから戻り値は違えどやってることは一緒」 的な事を耳にしますが全くもって違います。 まず、JavaScript で言う型とは何か? JavaScript はクラスを持ちません。よって型を作れません。 え? new Object() とかできるけど? var obj = new Object() として時の obj は確かにObject型のインスタンスオブ
// Numbers typeof 37 === "number"; typeof 3.14 === "number"; typeof 42 === "number"; typeof Math.LN2 === "number"; typeof Infinity === "number"; typeof NaN === "number"; // Despite being "Not-A-Number" typeof Number("1") === "number"; // Number tries to parse things into numbers typeof Number("shoe") === "number"; // including values that cannot be type coerced to a number typeof 42n === "bigint";
リリース、障害情報などのサービスのお知らせ
最新の人気エントリーの配信
処理を実行中です
j次のブックマーク
k前のブックマーク
lあとで読む
eコメント一覧を開く
oページを開く