JavaScript-2

通过parseInt()进行转换成整型
	test=parseInt('123');
	console.log(typeof test);   //123
	test=parseInt('234',0);
	console.log(test);			//234
	test=parseInt('0xabcdef');	//
	test=parseInt('012344');
	test=parseInt(45,16);	
	test=parseInt('356k8i23ng');
	test=parseInt('true');
	test=parseInt(true);
	test=parseInt('  35  6 a ');
	test=parseInt('44.666');
	console.log(test);
通过parseFloat()转换成浮点型
    只读一个点
        test=parseFloat('123.34.9abc');
	test=parseFloat('123');
	test=parseFloat('sdf');
	test=parseFloat(' 2e8a');
<2e8a>中e的作用是10的几次方
其它类型转换成字符串型
	test=String(1234);
	test=String(23.34);
	test=String('this is a test');
	test=String(true);
	test=String(false);
	test=String(null);
	test=String(undefined);
	test=String(NaN);

  

条件运算符
JavaScript 还包含了基于某些条件对变量进行赋值的条件运算符。
如果变量 visitor 中的值是 "PRES",则向变量 greeting 赋值 "Dear President ",否则赋值 "Dear"。
逻辑运算符
辑运算符用于测定变量或值之间的逻辑。
NaN 不是一个数值,不能和自己比较。<比较(==)>
比较运算符:
== 等于 x==8 为 false
=== 全等(值和类型) x===5 为 true;x==="5" 为 false
!= 不等于 x!=8 为 true
> 大于 x>8 为 false
< 小于 x<8 为 true
>= 大于或等于 x>=8 为 false
<= 小于或等于 x<=8 为 true
字符串连
例子:
<html>
<body>

<script type="text/javascript">
x=5+5; 结果:10
document.write(x);
document.write("<br />");
x="5"+"5"; 结果:55
document.write(x);
document.write("<br />");
x=5+"5"; 结果:55
document.write(x);
document.write("<br />");
x="5"+5; 结果:55
document.write(x);
document.write("<br />");
</script>

<h3>规则是:</h3>

<p><strong>如果把数字与字符串相加,结果将成为字符串。</strong></p>

</body>
</html>

posted on 2018-08-24 14:31  沉寂在未来  阅读(142)  评论(0编辑  收藏  举报

导航