标签:microsoft mic abc col 数据 ring span ros define
JavaScript有6中数据类型,分别为Number、String、Boolean、Object、undefined、function
1 <script type="text/javascript"> 2 var demo = 123; 3 document.write(demo + "的数据类型为:" + typeof (demo) + "<br />"); 4 demo = "456"; 5 document.write("‘" + demo + "‘的数据类型为:" + typeof (demo) + "<br />"); 6 demo = true; 7 document.write("‘" + demo + "‘的数据类型为:" + typeof (demo) + "<br />"); 8 demo = {};//数组、null返回的也是object类型 9 document.write("‘" + demo + "‘的数据类型为:" + typeof (demo) + "<br />"); 10 demo = undefined; 11 document.write("‘" + demo + "‘的数据类型为:" + typeof (demo) + "<br />"); 12 demo = function () { }; 13 document.write("‘" + demo + "‘的数据类型为:" + typeof (demo) + "<br />"); 14 </script>
1 var num = Number("aabc");//true转换为1 null转换位数字是0 undefined转换为数组是NaN 转换不成数字的转换为NaN 2 document.write(typeof (num) + ":" + num); 3 4 num = parseInt(true); //true false 转换全是NaN 5 document.write(typeof (num) + ":" + num); 6 7 //基底范围 2-36 8 num = parseInt(10,16); //把10当成16进制转换为10进制 以目标进制为基底转换为10进制 从数字位看到非数字位然后返回 砍断原则 例如100px 取100 9 document.write(typeof (num) + ":" + num); 10 11 num = parseFloat(10,16); //从数字位看到第一个.以后的数字返回 非数字断掉。 12 document.write(typeof (num) + ":" + num); 13 14 //转换string 15 num = String("123"); 16 document.write(typeof (num) + ":" + num); 17 18 19 //转换boolean 20 num = Boolean(123213); 21 document.write(typeof (num) + ":" + num); 22 23 24 num = "123"; //undefined null 不能tostring() 25 num = num.toString(); 26 document.write(typeof (num) + ":" + num); 27 28 29 num = 20; 30 num = num.toString(8); //以10进制为基底 转换为目标进制 31 document.write(typeof (num) + ":" + num); 32 33 34 //demo 2进制转为为10进制 35 36 num = 10000; 37 num = parseInt(num,2); 38 num = num.toString(16); 39 40 document.write(typeof (num) + ":" + num);
标签:microsoft mic abc col 数据 ring span ros define
原文地址:https://www.cnblogs.com/FashionDoo/p/10288931.html