<script type="text/javascript">
//变量声明全局
var temp;
var tmp2, tmp2 = 3;
function abc() {
alert(tmp2);
alert(a);//erro
//局部变量
var b = null;
var a;
alert(b); //undefined
alert(b == a);//true 值等于
alert(b === a);//false 严格等于
var c = 2.0;
alert((c.toString()).prototype)
alert(parseInt(c));//转换为Int类型
alert(parseInt("dfs123"));//截取 erro
alert(parseFloat('123abc'));//123
alert(parseFloat("0xA"));//0
alert(parseFloat("43.445.55"));//43.445
alert("abc".substring(1));//abc1
alert("abc".toUpperCase());//ABC
alert(123+'a' + c);//123a2.0
alert("abc".length);
var arr = "a-b-c".split("-");//[a,b,c]
for (var i = 0; i < arr.length; i++) {
alert(arr[i]);
}
alert("abc".search("b"));//1 坐标
//reg 正则表达式
var str = 'panguan- aidsjf-asdkjfh'
//方法一 /xxx/
var reg = /panguan/;
alert(reg.exec(str));//查找
alert(reg.test(str));//判断
//方法2 //new一个reg对象
var reg = new RegExp('panguan');
alert(reg.exec(str));
//array
var arr = [1,2,3,'abc',false];//任何类型
alert(arr);
var arr1 = new Array();
arr1[1] = 'abc'; //赋值
alert(arr1);
alert(arr1.length);
alert(arr1[0]);//undefined
alert(typeof(arr));
//运算符
5>2?alert(false):alert((true));
var a,b,c;
a = (b=5,c=2,d=3);
alert(a)//取最右边的
var e,f,g;
a = void(e=3,f=5,g=9);
alert(a);//a = undefined
alert(typeof(a));
alert(typeof(e));
var arr = [1,2,3];
alert(arr instanceof Array);
//其他的特殊语句
with(document){
write("第一句<br/>");
write("第二句<br/>");
write("第三句<br/>");
}
//try-cath
try{
if (c) {
throw new Error("错误呢");
}
}catch(e){
//TODO handle the exception
document.write(e.message + '<br/>')
}finally{
document.write("finally");
}
}
function abc(){
a; // a is not defined
alert(a);
}
</script>
网友评论