分类: 系统运维
2008-04-02 10:33:28
alert (parseInt("010"));//8基于8进制 alert (parseInt("010",2));//2 alert (parseInt("010",10));//10 alert (parseInt("0x10"));//16 alert (parseInt("2x10"));//2 alert (parseInt("123blue"));/123 alert (parseInt("blue123"));//NaN alert (parseInt("0x10",10));//0 |
parseFloat("1235blue");//1234.0 parseFloat("0xA");//NaN parseFloat("0908");//908.0 |
var oFalseObj=new Boolean(false); alert (typeof true);//boolean alert (typeof oFalseObj);//object返回的是顶层类型 var bResult=oFalseObj&true; alert (typeof bResult); alert(bResult); var oNumberObj=new Number(99); alert (typeof oNumberObj); //可以考虑js中存在原语类型如,number,boolean alert (typeof 99);//number alert (oNumberObj.toFixed(2));//99.00 //科学计数的方法表示 alert (oNumberObj.toExponential(1)); //toPrecision()根据最有意义的形式返回数字的预订形式 //或指定形式。 alert (oNumberObj.toPrecision(1));//`e+1 alert (oNumberObj.toPrecision(2));//99 |
valueOf~toString,charAt(var),charCodeAt(var); concat(var),indexOf(String),lastIndexOf(String); slice(Number,arg...)~substring(Number,arg); toLowerCase(),toUpperCase(),toLocaleLowerCase() toLocaleUpperCase(). |
var oStr=new String("hello world"); alert (oStr.slice(-3));//rld alert (oStr.substring(-10));//hello world alert (oStr.slice(3,-4));//lo w alert (oStr.substring(3,-4));//hel |
var oStr=new String("hello world"); alert (ostr instanceof String); #输出true |
var o=new Object; o.name="biaoflying";//为对象添加属性 alert (o.name); delete o.name;//删除对象的某个属性。 alert (o.hasOwnProperty("name"));//false |
var iNum1=25; var iNum2=~iNum1; alert(iNum2);//-26 |
var obj1=new Object; var numObj=new Number(33); var bl1=false,bl2=true; alert (obj1&&numObj); alert (numObj&&new Boolean(false)); alert(parseInt("rew32")&&new Boolean(true)); alert(bl1&&hello); alert(hello&&true); |
var v1="33",num=33; alert(v1!=num);//false alert(v1==num);//true alert(v1!==num);//true |
var v1="33",num=33; function doAdd(iNum){ alert (iNum+200); } function doAdd(iNum){ alert (iNum+20); } doAdd(v1); doAdd(num) #输出:3320,53.第二个方法覆盖了第一个方法。可以使用arguments对象避开该限制。 |
function sayHi(){ if(arguments[0]=="bye") return; else alert(arguments[0]); } function how_many_args(){ alert(arguments.length); } sayHi("biaoflying"); how_many_args(22,33,44,"hello"); #biaoflying #4 |
function doAdd(){ if(arguments.length==1) alert(arguments[0]); else{ var sum=0; for(var v=0;v //alert(sum); } alert(sum); } } doAdd(33,44,66); #143. |
var doAdd=new Function("iNum","alert(iNum+10);"); doAdd(50); var doAlsoAdd=doAdd; doAlsoAdd(10); function callAnotherFunc(fn,args){ fn(args); } callAnotherFunc(doAdd,100); alert(doAdd.length); alert(doAdd.toString()); |