前端知识复习(一)

1、js的数据类型:number、string、array、null、undefined、object、boolean、symbol(新增的)

   js的基本数据类型:number、string、undefined、boolean、null

      js的引用数据类型:object、array、function

  • 基本数据类型按值访问,操作的是他们的实际值;
  • 引用数据类型按引用访问,先从堆中取出内存地址,再按照指针所指向的方向,从栈中取出值。
  • tyepof主要用来检测基本数据类型,如果变量值是null或object,则typeof返回的是object;
  • typeof还可以返回function,可以这么理解:函数在ECMAScript中是一个对象,不是一种数据类型。
  • instanceof用来检测引用类型,可以检测到它是什么样的、具体的类型。
  • Object.prototype.toString.call(obj)用来检测任意类型。例如Object.prototype.toString.call(123); // [object Number]
数据类型 转化为true的值 转化为false的值
Boolean true false
String 任何非空字符串 “”(空字符串)
Number 任何非0的数值(包括无穷大) 0和NAN
Object 任何对象 null
Undefined 不适用 undefinded

2、js的一些小技巧

foo = foo || bar;
// 等价于
if (!foo) foo = bar; // 如果foo存在,值不变,否则把bar的值赋给foo
string转化为number
=‘45+new Date

猜你喜欢

转载自www.cnblogs.com/miacara94/p/9044517.html