首页 > 代码库 > 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);