zoukankan      html  css  js  c++  java
  • 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>

  • 相关阅读:
    mysql字符集
    zabbix自动发现zabbix_agent后添加到所属组和链接到某些模块(九)
    zabbix_agent添加到系统服务启动(八)
    苦苦的追寻,奈何~~(一年三份工作的总结)
    systemd service 设置limit,不生效问题
    logrotate
    cron定时任务
    crontab定时任务第一个周期未完成下一个周期执行就来了
    来年仍旧迷茫...
    rsync的daemon模式
  • 原文地址:https://www.cnblogs.com/85-Q/p/9509864.html
Copyright © 2011-2022 走看看