javascript基本知识

一、函数参数的个数

1 1234['toString']['length']
2 "1234"['toString']['length']
3 "1234".toString.length
4 "1234".toString().length
View Code

 二、关于catch

var a=1;
(function(){
   console.log(a);
   try{
      throw 2;
   }catch(e){
      var a = 2;
      console.log(a);
   }
   console.log(a);
})();


结果:
undefined 
2
2


var e=1;
(function(){
   console.log(e);
   try{
      throw 2;
   }catch(e){
      var e = 2;
      console.log(e);
   }
   console.log(e);
})();


结果:
undefined 
2
undefined
View Code

 三、substr与substring区别

"0123456789".substr(1,5);
=>"12345"
"0123456789".substring(1,5);
=>"1234"
View Code

String.substr(N1,N2) 这个就是我们常用的从指定的位置(N1)截取指定长度(N2)的字符串; 
String.substring(N1,N2) 这个就是我们常用的从指定的位置(N1)到指定位置(N2)的字符串;

四、函数命名表达式

(function func() {
      console.log('func');
})()
func();
View Code

 

posted on 2014-02-23 13:25  jian_xie  阅读(198)  评论(0编辑  收藏  举报