blackcore

本质的东西,深植于骨骼,扎根于灵魂! 淘实惠,各类电子版书籍

导航

javascript using the unary-plus and unary-minus operator 一元操作符

新手入门啊,看看就明白了!

<script src='jquery.js'></script>
......
<script>
var a=1;
var b='2';

//output number
console.log(typeof(-b));
console.log(
typeof(+b));
//output string
console.log(typeof(b));

//output 12
console.log(a + b);

//output 3
console.log(a + Number(b));
console.log(a
+ +b);
console.log(a
- -b);

//output -1
console.log(a + -b);
console.log(a
- +b);
</script>

posted on 2011-03-05 18:05  blackcore  阅读(408)  评论(0编辑  收藏  举报