script的学习3

基本类型:

<html>
<head>
<script type="text/javascript">
/* var box = "Lee";
var box2 = 'Lee';
alert(box);
alert(box2);
//单引号的双引号没有任何区别,必须成对出现,不能穿插
//引号必须成对出现,

*/ //string包含一些特殊的字符字面量,
// alert('Le\nle');

// alert('Le\rle'); //斜杠本身进行转义

//以十六机制表示一个
// alert('\x-1');
// \r \n
/*
var box = 'Mr';
box = box + 'Lee';
alert(box);

var box = 'Mr';
box = box + 'Lee' ;
alert(box);
*/
// toString --->可以把值转换为字符串
//toString可以传参
/*
var box = 10;
alert(box.toString());
alert(box.toString(2));
alert(box.toString(8));
alert(box.toString(10));
alert(box.toString(16));
*/
//转型的情况下,不可以完成none和undefined的转型
// var box ;
// alert(box.toString());
/*
var box;
alert(String(box));//字符串的undefined的类型
*/
// toString的类型的方法
// var box = null;
// alert(String(box));

//数据类型的最后一个类型Object
// var box = null;
// var box = {}; //对象自变量的创建
// alert(box);
// var box = new Object(); //通过New来创建一个对象
// alert(box);
// var box =new Object; //不推荐这种写法
// alert(box);
/*
var box =new Object(2); //会执行toString方法
alert(box);//2是对象类型
alert(typeof(box));

var age= 100 ;
alert(box+age);
*/
var box = new Number();
alert(typeof(box));
alert(box);
var age =100;
alert(age+box);
var box = new String('Lee');
alert(box);

//面向对象是一个很深的知识
</script>
</head>
<body>
</body>
</html>

posted @ 2012-11-17 00:12  sgsheg  阅读(131)  评论(0)    收藏  举报