JS基础知识

41 阅读1分钟

类型判断

js类型分为 原始类型(string、symbol、boolean、number、null、bigint)和对象类型。

  1. typeof(缺点: 对象类型除了函数都不行。原始类型null 无法判断,可以用variable来弥补)
  2. instanceof
  3. Object.prototype.Tostring.call
typeof 1 //number

var str1 = new String('hello world') 
str1 instanceof String // true 

Object.prototype.Tostring.call(1) //[object Number]

类型转化

image.png

原始类型存储位置

局部变量被存储在栈上,全局变量存储在静态区域上,其它都存储在堆上。