JS学习笔记--《数值与字符串相加篇》

<script type="text/javascript">
  //数值与字符串相加
  var a=5,b=2,c="4";
  document.write(a+c+"<br/>");//数值与字符串相加 54
  document.write(a+parseFloat(c)+"<br/>");//c通过parseFloat()方法转化为字符串 9
  document.write(a+(c-0)+"<br/>");//字符串转化为数值然后再相加 9
  document.write(a.toString()+b.toString()+"<br/>");//a、b通过toString()方法转化为字符串 52
 </script>

 

输出得到:

54
9
9
52

posted @ 2012-03-26 14:53  闫森  阅读(766)  评论(1编辑  收藏  举报