Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JavaScript 数据类型和类型判断 #1

Open
zzddlalala opened this issue Mar 30, 2023 · 1 comment
Open

JavaScript 数据类型和类型判断 #1

zzddlalala opened this issue Mar 30, 2023 · 1 comment

Comments

@zzddlalala
Copy link
Owner

动态和弱类型

  • 动态语言,变量与任何特定值类型没有任何关联,并且任何变量都可以分配(重新分配)所有类型的值;
  • 弱类型语言, 当操作涉及不匹配的类型是否,它将允许隐式类型转换。

原始类型(Undefined、Null、Boolean、Number、BigInt、String 和 Symbol)

  • `typeof void 0 === 'undefined'
  • type of null === 'object', 应用===判断
  • type of NaN === 'number'
  • const a = BigInt(), type of 1n === 'bigint'
  • typeof Symbol() === 'symbol'

复杂类型(Object)

//判断function
typeof funtion test() {}  === 'function'
//判断Array
Object.prototype.toString.call([]) ==='[object Array]'
//判断Date
console.log(Object.prototype.toString.call(date)) // [object Date]
Array.isArray([]) === true
//instanceof 运算符用来检测 constructor.prototype 是否存在于参数 object 的原型链上。
object instanceof constructor 
@zzddlalala
Copy link
Owner Author

类型转换

mqyqingfeng/Blog#159
mqyqingfeng/Blog#164

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant