变量类型和计算

xiaoxiao2021-02-28  113

变量类型 值类型 :数值,布尔值,null,undefined

把一个值类型(也可以叫基本类型)store2传递给另一个变量(赋值)时,其实是分配了一块新的内存空间,因此改变store1的值对store2没有任何影响

引用类型:对象,数组,函数

store2只进行了一次赋值,理论上它的值已定,但后面通过改写store1的值,发现store2的值也发生了改变,这正是引用类型的特征

强制类型转换 1.字符串拼接

var a = 100 + 10 //110 var b = 100 + '10' //10010

2.==运算符

100 == '100' //true 0 == '' //true null == undefined //true

3.if语句

var a = true if(a){ //可以运行,会转成布尔值true } var b = '' if(b){ //不会执行,转成了false}

4.逻辑运算

console.log(10 && 0) //把10转换成true,输出了0 console.log('' || 'abc') //'abc' console.log(!window.abc) //true 判断一个变量是true还是false var a = 100 console.log(!!a)

Typeof运算符 typeof undefined =>undefined typeof ‘abc’ =>string typeof 123 =>number typeof true =>boolean typeof [ ] =>object typeof { } =>object typeof null =>object typeof console.log =>function

转载请注明原文地址: https://www.6miu.com/read-30850.html

最新回复(0)