覚書
typeofで型を判別できる & 型は以下のような種類がある。
typeof undefined //'undefined'
typeof 0 //'number'
typeof true //'boolean'
typeof "foo" //'string'
typeof Symbol("id") //'symbol'
typeof Math //'object'
typeof null //nullは'object'になる (実際はnullはobjectじゃない。typeofの問題、nullはnull)
typeof console.log //'function'
またtypeofはtypeof(x)ともtypeof xともかける。
型変換
String(123)という風にかくと123は”123″になる (文字列)
“123”を123にするにはNumber(“123″)
Bloolean(x)でブール値に変換することもできます。
Boolean(x)では0, null, undefined, NaNはfalseとなり”0”, “false”, 1などはtrueとなります。
コメントを残す