标签:console log 数据类型 js --- typeof b2 true b1
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>01_数据类型</title> </head> <body> <!-- 1. 分类(2大类) * 基本(值)类型 * Number: 任意数值 * String: 任意文本 * Boolean: true/false * undefined: undefined * null: null * 对象(引用)类型 * Object: 任意对象 * Array: 特别的对象类型(下标/内部数据有序) * Function: 特别的对象类型(可执行) 2. 判断 * typeof: * 可以区别: 数值, 字符串, 布尔值, undefined, function * 不能区别: null与对象, 一般对象与数组 * instanceof * 专门用来判断对象数据的类型: Object, Array与Function * === * 可以判断: undefined和null --> <script type="text/javascript"> // typeof: 返回的是数据类型的字符串表达形式 //1. 基本类型 var a console.log(a, typeof a, a===undefined) // undefined 'undefined' true console.log(a===typeof a) // false a = 3 console.log(typeof a === 'number') a = 'atguigu' console.log(typeof a === 'string') a = true console.log(typeof a === 'boolean') a = null console.log(a===null) // true console.log(typeof a) // 'object' console.log('--------------------------------') //2. 对象类型 var b1 = { b2: [2, 'abc', console.log], b3: function () { console.log('b3()') } } console.log(b1 instanceof Object, typeof b1) // true 'object' console.log(b1.b2 instanceof Array, typeof b1.b2) // true 'object' console.log(b1.b3 instanceof Function, typeof b1.b3) // true 'function' console.log(typeof b1.b2[2]) // 'function' console.log(b1.b2[2]('abc')) // 'abc' undefined </script> </body> </html>
标签:console,log,数据类型,js,---,typeof,b2,true,b1 来源: https://www.cnblogs.com/leiyanting/p/15249776.html
本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享; 2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关; 3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关; 4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除; 5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。