js 总结四 07-12

switch

switch(n)
{
case 1:
  执行代码块 1
  break;
case 2:
  执行代码块 2
  break;
default:
  n 与 case 1 和 case 2 不同时执行的代码
}
default 关键词来规定匹配不存在时做的事情
实例:
var day=new Date().getDay();
switch (day)
{
case 0:
  x="Today it's Sunday";
  break;
case 1:
  x="Today it's Monday";
  break;
case 2:
  x="Today it's Tuesday";
  break;
case 3:
  x="Today it's Wednesday";
  break;
case 4:
  x="Today it's Thursday";
  break;
case 5:
  x="Today it's Friday";
  break;
case 6:
  x="Today it's Saturday";
  break;
}

typeof
判断类型

var num=function(){};
console.log(typeof(num));

类型转换

Number(mix)
列:
var a=Number("123");把字符转为数子
parseint(string,radix)
列:
var a=parseint('123.9',10);把里面东西转成整形 radix进制
parseFloat(string)
列:
var str=123.6;
var a=parseFloat(str)正常数
toString(radix)
列:
var str=123;
var a=str.toString();
String(mix)
列:
var str=123;
var a=toString(str);转成字符
Boolean()
列:
var str='';
var a=Boolean(str);转成布尔

你可能感兴趣的