ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

面向对象(typeof)

2022-06-04 15:04:38  阅读:98  来源: 互联网

标签:console log alert 面向对象 typeof var undefined


//面向对象:交给谁去干
//面向过程:将步骤分解,交给对象去干
//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));

  

标签:console,log,alert,面向对象,typeof,var,undefined
来源: https://www.cnblogs.com/wsx123/p/16341863.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有