欢迎来到贱贱的博客

扩大
缩小

javascript笔记2之数据类型

  1 /*
  2 var box;
  3 alert(typeof box);        //box是Undefined类型,值是undefined,类型返回的字符串是undefined
  4 
  5 var box = true;
  6 alert(typeof box);        //box是Boolean类型,值是true,类型返回的字符串是boolean
  7 
  8 var box ='hhh';
  9 alert(typeof box);        //box是String类型,值是'李炎恢',类型返回的字符串是string
 10 
 11 var box = 250;
 12 alert(typeof box);        //box是Number类型,值是250,类型返回的字符串是number
 13 
 14 //空的对象,表示这个对象创建了,里面没东西
 15 //空对象,表示没有创建,就是一个null
 16 
 17 var box = {};
 18 alert(typeof box);        //box是Object类型,值是[object Object],类型返回的字符串是object
 19 
 20 var box = null;
 21 alert(typeof box);        //box是Null类型,值是null,类型返回的字符串是object
 22 
 23 var box = new Object();
 24 alert(box);        //box是Object类型,值是[object Object],类型返回的字符串是object
 25 
 26 
 27 function box() {
 28 
 29 }
 30 alert(typeof box);        //box是Function函数,值是function box() {},类型返回的字符串是function
 31 
 32 alert(typeof new Object());   //可以直接使用字面量
 33 
 34 var box = undefined;        //没有必要
 35 alert(box);
 36 
 37 
 38 var box;
 39 alert(typeof box);
 40 alert(typeof age);        //以后必须声明一个变量就必须初始化,以避免这种问题
 41 
 42 var box = {};
 43 
 44 if (box != null) {    //不等于null,说明不是空对象
 45     alert('对象已经创建成功!');
 46 }
 47 
 48 var box = null;        //这个表示,你还没有创建对象,但先声明了对象引用而必须初始化的结果
 49                             //你还没有来得及创建对象,先声明一个对象的变量放在那边,默认初始化为null
 50 
 51                             
 52 var box = null;
 53 
 54 box = {
 55     1:1
 56 };
 57 
 58 alert(box);
 59 
 60 var box = ''; //创建一个字符串变量,一开始不知道初始化什么字符串,所以,就给他一个空字符串初始化
 61 
 62 var box = 0;                //数值初始化,一般用0
 63 
 64 var box = false;        //布尔值初始化,一般一开始用false或者true
 65 
 66 alert(undefined == null);        //他们都是空的,所以相等理所当然,
 67 
 68 alert(undefined === null);         //数据类型也必须相等才可以
 69 
 70 alert(typeof undefined == typeof null);
 71 
 72 var box = true;
 73 alert(typeof box == typeof 1);
 74 
 75 var box = '';
 76 
 77 alert(Boolean(box));
 78 
 79 */
 80 
 81 
 82 
 83 var box;
 84 
 85 if (box) {           //条件语句里的()里必须是布尔值,true或者false
 86     alert('真');
 87 } else {
 88     alert('假');
 89 }
 90

/* var box = "Lee"; var box2 = 'Lee'; alert(box+box2);//连接符

var box = 'Lee";  //引号必须成对 alert(box);

alert('\t\\L\'e\ne\"')

 

alert('\x41');

alert('\u03a3');

var box = 'Mr.'; box = box + ' Lee'; alert(box);

var box = true; alert(box.toString());  //   'true'

var box = 10; alert(box.toString()); alert(box.toString(2));   // '1010' alert(box.toString(8));   // '12' alert(box.toString(10));   // '10' alert(box.toString(16));   // 'a'

var box; alert(String(box));   // 'null'  //  'undefined'

var box = null;

var box = {};   //对象字面量的创建方法 alert(typeof box);

var box = new Object();   //通过new创建一个对象 alert(typeof box);

var box = new Object(2); var age = 100; alert(box + age);

var box = new Number(60);   //这种方法也是创建一个数值对象 alert(box);

 var box = new String('Lee');  //var box = 'Lee';  alert(typeof box);

*/

 

posted on 2017-01-03 16:25  L的存在  阅读(163)  评论(0)    收藏  举报

导航