JavascriptでBooleanからintへの型変換
intからBooleanへはよく変換するが、逆のパターンは知らなかったのでメモ。
これが一番いいかも。
var boolValue = true; var intValue = +boolValue; alert(intValue);// 1 が出力される boolValue = false; intValue = +boolValue; alert(intValue);// 0 が出力される
参考にしたページ
Posted on 2011/11/16, in 開発 and tagged Javascript. Bookmark the permalink. Leave a Comment.
Leave a Comment
Comments (0)