zoukankan      html  css  js  c++  java
  • 数值转换题

    一,  请写出下列表达式的值
          var a = 5;      var b = 0;
          (1)"" + a - b;    _____5_______            
          (2)typeof ("" + a - b);    ___number________		
          (3)Boolean(a) - b;    _____1______
    
    
         var n = null;	 var m;
          (4) typeof(n);     ____object_____			
          (5) typeof(m);    ____undefined_____	 		
          (6) Number(n) + Number(m); _____NaN_______
          (7) Boolean(n) - Boolean("n");  _____-1_______ 	
          (8) Boolean(m) - Boolean(n);  _____0________		
          (9) m--;      ____NaN_______
          (10) +n;     _____0______
    二  填空题
         (1) 数组中可以添加元素,但是不会修改原数组的方法是 ____concat______, 可以向数组中的任意位置添加元素的方法是____splice______
         (2) 只能以__字母____,  __下划线_____,  __$_____作为变量名的开头
         (3) 数组的三要素 : __下标_____,  ___元素____, __数组长度______
         (4) 结束循环语句的关键字是___break_____, 结束本轮循环的关键字是 ___continue______
         (5) 假如price = 900,    "price > 500 && price *= 0.8" 这句代码的运行结果是__720_____
    
    逻辑与的短路运算 : 
    var res = undefined || null || 0 || 10 || 1 || '';
    console.log ( res );
    	        10
    var res =  100 && null && 0 && 10 && 1 && '';
    console.log ( res );
    		null
    var age1 = 10;
    var age2 = 10;
    var res1 = typeof(age1) && age1 + age2;		20
    var res2 = typeof(age1) || age1 + age2;		10
    var res3 = (age1 - age2) && age1 +age2;		0
    var res4 = (age1 - age2) || age1 +age2;		20
    
    var  c = 12;
    var res1 = " " && c;	12
    var res2 = "NaN" && c;			12
    var res3 = undefined || c + "c";	12c
                                                                                                console.log ( Number ( "123.1.1abc" ) );  NaN
    console.log ( parseInt ( "123.1.1abc" ) );   123
    console.log ( parseFloat ( "123.1.1abc" ) );  123.1
    
    console.log ( Number ( false ) );  0
    console.log ( Number ( undefined ) );  NaN
    
    
    console.log(+null);  0
    console.log(+"false");  NaN
    console.log(+false);    0
    console.log(+undefined);  NaN
    console.log(+"number");  NaN            
    
        var a = 5;
        var b = 0;
        console.log ( a+b );			5
        console.log ( typeof (a+b) );		number
        console.log ( a-b );			5
        console.log ( typeof (a-b) );		number
        console.log ( a-Boolean(b) );		5
        console.log ( typeof (a-Boolean(b)) );	number
        console.log ( Boolean(a)-b );		1
        console.log ( typeof (Boolean(a)-b) );	number
    
    
        console.log ( Boolean ( 0 ) );		flase
        console.log ( Boolean ( 0.0 ) );		flase
        console.log ( Boolean ( "0" ) );		true
        console.log ( Boolean ( null ) );		flase
        console.log ( Boolean ( "null" ) );		true
        console.log ( Boolean ( false ) );		flase
        console.log ( Boolean ( undefined ) );	flase
        console.log ( Boolean ( ' ' ) );		true
        console.log ( Boolean ( NaN ) );		flase
        console.log ( Boolean ( "false" ) );	true
        console.log ( Boolean ( "undefined" ) );   	true  
    
    转成数字类型
    parseInt(".123abc");  NaN
    parseFloat(".12.3abc");  0.12
    parseInt(123);   123
    parseFloat(123);  123
    parseInt(123.25);  123
    parseFloat(123.25); 123.25
    
    console.log ( Number ( "123" ) );   123
    console.log ( Number ( "123.1.1abc" ) );  NaN
    console.log ( parseInt ( "123.1.1abc" ) );   123
    console.log ( parseFloat ( "123.1.1abc" ) );  123.1
    
    console.log ( Number ( false ) );  0
    console.log ( Number ( undefined ) );  NaN
    
    
    console.log(+null);  0
    console.log(+"false");  NaN
    console.log(+false);    0
    console.log(+undefined);  NaN
    console.log(+"number");  NaN
    
    
    
        var a = 5;
        var b = 0;
        console.log ( a+b );			5
        console.log ( typeof (a+b) );		number
        console.log ( a-b );			5
        console.log ( typeof (a-b) );		number
        console.log ( a-Boolean(b) );		5
        console.log ( typeof (a-Boolean(b)) );	number
        console.log ( Boolean(a)-b );		1
        console.log ( typeof (Boolean(a)-b) );	number
    
    
       console.log ( Boolean ( 0 ) );		flase
        console.log ( Boolean ( 0.0 ) );		flase
        console.log ( Boolean ( "0" ) );		true
        console.log ( Boolean ( null ) );		flase
        console.log ( Boolean ( "null" ) );		true
        console.log ( Boolean ( false ) );		flase
        console.log ( Boolean ( undefined ) );	flase
        console.log ( Boolean ( ' ' ) );		true
        console.log ( Boolean ( NaN ) );		flase
        console.log ( Boolean ( "false" ) );	true
        console.log ( Boolean ( "undefined" ) );   	true    
    
    console.log ( Number ( "123" ) );   123
    console.log ( Number ( "123.1.1abc" ) );  NaN
    console.log ( parseInt ( "123.1.1abc" ) );   123
    console.log ( parseFloat ( "123.1.1abc" ) );  123.1
    
    console.log ( Number ( false ) );  0
    console.log ( Number ( undefined ) );  NaN
    
    
    console.log(+null);  0
    console.log(+"false");  NaN
    console.log(+false);    0
    console.log(+undefined);  NaN
    console.log(+"number");  NaN
    
    
    
        var a = 5;
        var b = 0;
        console.log ( a+b );			5
        console.log ( typeof (a+b) );		number
        console.log ( a-b );			5
        console.log ( typeof (a-b) );		number
        console.log ( a-Boolean(b) );		5
        console.log ( typeof (a-Boolean(b)) );	number
        console.log ( Boolean(a)-b );		1
        console.log ( typeof (Boolean(a)-b) );	number
    
    
       console.log ( Boolean ( 0 ) );		flase
        console.log ( Boolean ( 0.0 ) );		flase
        console.log ( Boolean ( "0" ) );		true
        console.log ( Boolean ( null ) );		flase
        console.log ( Boolean ( "null" ) );		true
        console.log ( Boolean ( false ) );		flase
        console.log ( Boolean ( undefined ) );	flase
        console.log ( Boolean ( ' ' ) );		true
        console.log ( Boolean ( NaN ) );		flase
        console.log ( Boolean ( "false" ) );	true
        console.log ( Boolean ( "undefined" ) );   	true  
    
    隐式数据类型转换
    console.log ( 1 + "true" );		1true
    console.log ( 1 + undefined );  	NaN
    console.log ( 1 + null ); 		1
    console.log ( 1 + false );		1
    console.log ( 1 + NaN ); 		NaN
    console.log ( 1 + "null" ); 		1null
    console.log ( 1 + "10" ); 		110
    console.log ( "1" + 10 ); 		110
    console.log ( "1" + (10 + 1) );		111
    console.log ( "1" + 10 + 1 );``		1101
    console.log ( 10 + 1 + "1" );		111
    console.log ( !10 );			flase
    console.log ( !"10" );			flase
    console.log ( !"0" );			flase	
    console.log ( !0 );			true
    console.log ( !"null" );		flase	
    console.log ( !"" );			true
    console.log ( !"  " );			flase 
    

      

  • 相关阅读:
    Java面向对象(02)--封装
    Java面向对象(01)--初识
    Java基础(10)--数组
    Java基础(09)--方法
    python中format输出常用的3种格式
    python 查找列表中重复元素以及重复元素的次数
    HttpRunner六:创建run.py文件,执行套件并生成测试报告
    HttpRunner五:关联参数的应用,获取上一个接口的返回值,用于当前接口的请求值
    HttpRunner四:testcases、testsuites以及参数化的使用
    HttpRunner中在case2中,使用作为请求参数和预期结果,预期结果中值显示是:LazyString($变量key)
  • 原文地址:https://www.cnblogs.com/zycs/p/12158396.html
Copyright © 2011-2022 走看看