首页 > 代码库 > javascript中的数据类型
javascript中的数据类型
var result = typeof(null);document.write("typeof null =" + result); // objectdocument.write("</br>");上面result的结果是object
var sum = "1" + 2 + 3;document.write("‘1‘ + 2 + 3 = " + sum); // 123document.write("</br>");var sum1 = "64" - 4;document.write("‘64‘ - 4 = " + sum1); // 60document.write("</br>");var sum2 = NaN * 4;document.write("NaN * 4 = " + sum2); // NaNvar result1 = void(0);document.write("</br>");document.write("void(0) = " + result1); // undefinedvar result2 = null * 45;document.write("</br>");document.write("null * 45 = " + result2); // 0var result3 = 13 | 5; document.write("</br>");document.write("13 | 5 = " + result3); // 13var result4 = 13 & 5; document.write("</br>");document.write("13 & 5 = " + result4); // 5var result5 = 13 >> 2; document.write("</br>");document.write("13 >> 2 = " + result5); // 3var result6 = -13 >> 2; document.write("</br>");document.write("-13 >> 2 = " + result6); // -4var result7 = 13 << 2; document.write("</br>");document.write("13 << 2 = " + result7); // 52var result8 = -13 << 2; document.write("</br>");document.write("-13 << 2 = " + result8); // -52var str = "abdc.#dfe.%^%$";str = str.toUpperCase();document.write("</br>");document.write("str.toUpperCase = " + str); // ABDC.#DFE.%^%$var num1 = parseInt("28");document.write("</br>");document.write("parseInt(‘28‘) = " + num1); // 28var num2 = parseInt("028");document.write("</br>");document.write("parseInt(‘028‘) = " + num2); // 2 (注意:8进制的数不能有8和9)var num3 = 11;var str1 = num3.toString(2);document.write("</br>");document.write("十进制数11变为2进制 = " + str1); // 01111011var str4 = "hello world!";str4.replace(/world/,"my friend"); // hello worlddocument.write("</br>");document.write("str4 = " + str4);
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。