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对象

 
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值