• 面向对象(typeof)


    //面向对象:交给谁去干
    //面向过程:将步骤分解,交给对象去干
    //typeof 可以打印出值属于那种数据类型的 number 数字 string 字符 boolean true/false 真和假 object null/[] undefined function
    // var n = 123;
    // var n = "123";
    // var n = [];
    // var n = undefined;
    // console.log(typeof (n));

    可以将任何数据转换成自己想要的数据类型
    // number(值) undefined不能转换为数字 组合使用数字+abc也不能转换为数字
    // var n = Object("123");
    // console.log(typeof(n) + ":" + n);
    //parseInt(值,radix) 2-36进制 30=16乘3 将小数转化为整形 其他都为NaN
    // var n = parseInt(1.1111);
    // console.log(typeof(n) + ":" + n);
    // var n = parseInt(30,16);
    // console.log(typeof(n) + ":" + n);
    // var n = parseInt("100px");
    // console.log(n);

    //parseFloat 浮点型 只取数字
    // var n = parseFloat("100.2.123asam");
    // console.log(typeof(n) + ":" + n );

    //String 转换为字符串
    // var n = String(123);
    // console.log(typeof(n) + ":" + n );

    //Boolean 转换为真或假 只能是数字或者字符串
    // var n = Boolean(1);
    // console.log(typeof(n) + ":" + n);

    //2进制转换为10进制转换为16进制
    // var n = parseInt(1 , 16);
    // console.log(typeof(n) + ":" + n);

    //隐式类型转换方法:
    // null false undefined true
    // console.log(isNaN(null));
    //++/-- +/- (一元正负) 可以将字符串类型转化成number类型
    // var n = + "1";
    // console.log(typeof(n) + ":" + n )
    //+
    // var n = "3" + 10;
    // console.log(n);




    //alert(typeof(a)); //undefined //alert(typeof(undefined)) //undefined //alert(typeof(NaN)); //number //alert(typeof(null)); //object // var a = '123abc'; //alert(typeof(+a)); //number //alert(typeof(!!a)); //boolean //alert(typeof(a + "")); //string //alert("11"+11); //1111 //alert(1 == "1"); //true //alert(1 === "1") //false 三个等于为绝对等于 //alert(NaN == NaN) //false //alert(NaN == undefined) //false //alert(parseInt("123abc"))//123 // var num = 123123.345789; // alert(num.toFixed(1));

      

  • 相关阅读:
    20150805-20150807 tradeDate-----python
    nutz_web应用中主页跳转到登录页面的方式
    nutz中实现登录验证
    C#之继承
    C#中Page执行顺序:OnPreInit()、OnInit()……
    利用堆栈实现走迷宫算法
    对数组结构体按照K值翻转
    实现多项式的加法和乘法运算
    两个有序链表的合并
    队列的比较和存储方式
  • 原文地址:https://www.cnblogs.com/wsx123/p/16341863.html
Copyright © 2020-2023  润新知