Knowledge points of data type, ==, ===, typeof, instanceof, null, undefined, etc. in javaScript

Directly upload code and screenshots 

The results of the operation are as follows:

<script type="text/javascript">
var v1 = {};
var roles = ['任盈盈', '黄蓉', '周芷若'];
var citys = new Array('香港', '深圳', '澳门');
var superStars = new Array(3);
superStars[0] = "范冰冰";
superStars[1] = "关晓彤";
superStars[2] = "古力娜扎";
//object object object object
console.log(typeof v1, typeof roles, typeof citys, typeof superStars);
//object object object object
console.log(typeof(v1), typeof(roles), typeof(citys), typeof(superStars));
console.log(citys instanceof Array, citys instanceof Object);//true true
console.log([] instanceof Array, [] instanceof Object) // true true
console.log({} instanceof Object, {} instanceof Array) // true false
// console.log((()=>{}) instanceof Function) // true
console.log("******************************");

var x = 7;
var y = false; // 0
var z = true; // 1
//布尔型和数字型相加的时候,true的值为1,false的值为0
console.log(x + y, x + z);//7 8

var s1;
var s2 = null;
var s3 = 666.55;
var s4 = 888;
var s5 = {};
var s6 = [];
var s7 = true;
var s8 = "于都县";
//undefined object number number
console.log(typeof s1, typeof s2, typeof s3, typeof s4);
//object object boolean string
console.log(typeof s5, typeof s6, typeof s7, typeof s8);

//==和===区别: ==只比较值,(===其实就是严格等,也叫严等,===既比较值也比较类型)
//==运算符,会发生隐式类型转换
//true true true true true true
console.log(100 == '100', 0 == '', 0 == false, 1 == true, false == '', false == "");
//false false false false false false
console.log(100 === '100', 0 === '', 0 === false, 1 === true, false === '', false === "");

//通常我们在所有地方都使用===,在判断null或者undefined时使用==
//true false
console.log(null == undefined, null === undefined);
var t;
//true true
console.log(t == undefined, t == null);
//true false
console.log(t === undefined, t === null);
//t == null相当于(t === null || t === undefined)
console.log(t == null, (t === null || t === undefined));//true true

console.log(null == Object, null === Object);//false false
//boolean object false false
console.log(typeof (null === Object), typeof null, typeof null === Object, typeof null == Object);
//false false
console.log(typeof null === null, typeof null == null);
//true true
console.log(typeof null === 'object', typeof null == 'object');
//true true
console.log(typeof null === "object", typeof null == "object");
</script>

In javaScript, there are many trivial knowledge points, and I will write other knowledge points when I have time in the future.

I'm a bit lazy recently, writing articles is a bit like keeping a running account, it's not good!

Guess you like

Origin blog.csdn.net/czh500/article/details/115144367