js基础巩固之--变量类型以及声明

来源:互联网 发布:域名可以一年一年续费 编辑:程序博客网 时间:2024/06/05 03:33

          在只求达到目的的同时,却丢失了坚实的基础,深知自己的基础有待加强。目前主要学习的书籍是《javascript高级编程设计(第三版)》,本博文笔记是第三章第三小节--数据类型(p23)。

      本博文用到的知识点:变量的声明和赋值,变量的类型的检测(typeof),对象的遍历(for in),JS中arguments对象。

      本文宗旨:总结所学到的知识点,得到大神的指点/纠错,给予和我一样的菜鸟一些帮助!

      线上代码演示地址:http://runjs.cn/code/n9chq2bo

     JScode

window.onload = function(){var obj = {//声明测试对象    _string     : "字符串",    _number1    : 12345,    _number2    : 1.3,    _boolean    : true,    _undefined  : undefined,    _null       : null,    _array1     : new Array(3),    _array2     : [],    _array3     : [1,2,3,4],    _object1    : new Object(),    _object2    : {},},objTypeof = {};//声明测试类型对象for(var x in obj){objTypeof[x] = typeof(obj[x]);//注意,typeof是操作符,并不是方法//以上代码同等于//objTypeof[x] = typeof obj[x];}for( var index in obj){document.write(index+'------'+obj[index]+'</br>');}document.write('=========================</br>');for( var index in objTypeof){document.write(index+'------值类型为:'+objTypeof[index]+'\n </br>');}document.write('=========================</br>');Write('五种基本数据类型','Undefined','Null','Boolean','NUmber','String');function Write(){for(var index in arguments){//arguments对象,是JS隐式对象,不能显式声明,函数执行时才可用document.write(arguments[index]+',');}}//访问对象属性的两种方式,注意第二种是中括号里字符串console.log(obj._string);console.log(obj['_string']);//访问没有定义的变量//console.log(aaa);//直接报错var bbb;//声明未赋值console.log(bbb);//返回undefined}
努力一点,生活更美好!

0 0
原创粉丝点击