強制変換データタイプ

783 ワード

強制変換データタイプ/1 var str 1="hello"var res 1=str 1+10;consolone.log(res 1)consolie.logs(typeof res 1)//ストリングス
//2
var str2 = '100';
var res2 = str2 - 20;//'- '
console.log(res2);
console.log(typeof res2);//number           

//3
var str3 = '99';//string
var res3 = Number(str3);
console.log(res3);
console.log(typeof res3);//number

//4
var str4 = "100px";//string
var res4 = parseInt(str4);//      
console.log(res4);
console.log(typeof res4);//number

//5
var str5 = "100.5px";
var res5 = parseFloat(str5);//    number;
console.log(res5);
console.log(typeof res5);//number

//6
var str6 = "abc10.5efg";
var res6 = parseFloat(str6);
 console.log(res6);//NaN : Not a Number
 console.log(typeof res6);//number