var married = true;
alert("1." + typeof(married)); //1.boolean
married = "true";
alert("2." + typeof(married)); //2.string
var a = 3;
var b = a + "";
var c = a.toString();
var d = "student" + a;
alert(typeof(a) + " " + typeof(b) + " " + typeof(c) + " " + typeof(d)); //number string string string
String
sString=$.trim(sString); java string
"hello".charAt( 0 ) // "h"
"hello".toUpperCase() // "HELLO"
"Hello".toLowerCase() // "hello"
"hello".replace( /e|o/g, "x" ) // "hxllx"
var sMyString = "Tsinghua University"; document.write(sMyString.slice(1,3) + "<br>"); si document.write(sMyString.substring(1,3) + "<br>"); //si document.write(sMyString.slice(4) + "<br>");//ghua University document.write(sMyString + "<br>"); //Tsinghua University"1,2,3".split( "," ) // [ "1", "2", "3" ]
var sMyString = "Tsinghua University"; document.write(sMyString.slice(1,3) + "<br>"); // si document.write(sMyString.substring(1,3) + "<br>"); // si document.write(sMyString.slice(4) + "<br>"); // ghua University substr() document.write(sMyString + "<br>"); //Tsinghua University
var sMyString = "Tsinghua University"; document.write(sMyString.slice(2,-3) + "<br>"); //inghua Univers document.write(sMyString.substring(2,-3) + "<br>"); //Ts document.write(sMyString.substring(2,0) + "<br>"); //Ts document.write(sMyString + "<br>"); //inghua Univers
document.write(sMyString.indexOf("i")+"<br>"); //2 at() in()
document.write(sMyString.indexOf("i",3)+"<br>"); //11 document.write(sMyString.lastIndexOf("i")+"<br>"); //16 document.write(sMyString.lastIndexOf("i",3)+"<br>"); //2 document.write(sMyString.lastIndexOf("V")+"<br>"); // -1
Numeric
<script type="text/javascript">
x=5+5;
document.write(x); //1
x="5"+"5";
document.write(x); //2
x=5+"5";
document.write(x); //3
x="5"+5;
document.write(x); //4
</script>
answer :
10555555
var mynum1 = 23.345;
var mynum2 = 45;
var mynum3 = -34;
var mynum4 = 9e5;
alert(mynum1 + " " + mynum2 + " " + mynum3 + " " + mynum4); // 23.345 45 -34 900000
var fNumber = 895.4;
alert(fNumber.toExponential(1)); //9.0e+2
alert(fNumber.toExponential(2)); //8.95e+2
沒有留言:
張貼留言