JS值类型、引用类型、强制类型转换

1、js中的数据类型

js中有5中简单数据类型(也称为基本数据类型): Undefined、Null、Boolean、Number和String。一种复杂类型:Object

2、js变量按照存储类型分为值类型和引用类型

值类型: string number boolean undefined
引用类型: Object Array Function //数组和函数本质上也是对象
区别 
值类型                        引用类型
    var a = 100;                var a = {age: 100,name: '张三'}
    var b = a;                  var b = a;
    a = 200;                    a.age = 200;
    console.log(b) // 100       console.log(b) // Object {age: 200, name: "张三"}

3、变量计算-强制类型转化

· 字符串拼接   100 + '' // '100'
· == 运算     null == undefined // true
· if语句
· 逻辑运算

if语句
var a = true;
if(a){
    //..
}
var b = '';
if(b){
    //...
}
var c = 100;
if(c){
    //...
}
其中b、c都转化为了布尔值

逻辑运算
console.log(10 && 0); // 0
console.log( '' || 'abc'); // 'abc'
console.log(!window.abc) //true
// 判断一个变量会被当做true还是false
var a = 100;
console.log(!!a); // true

4、js中使用typeof能得到的类型

typeof undefined // undefined
typeof 'abc' // string
typeof 123 // number
typeof true // boolean
typeof {} // object
tyoepf [] // object
typeof null //object
typeof console.log //function

5、js中有哪些内置函数-数据封装类对象

Object
Array
Boolean
Number
String
Function
Date
RegExp
Error

6、如何理解JSON

//json 是一个js内置对象,类似Math
// json也是一种数据格式
JSON.stringify({a:10,b:100}); js对象转json
JSON.parse('{"a":10,"b":100}'); json转js对象

 
    原文作者:zer0_li
    原文地址: https://segmentfault.com/a/1190000010828705
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞