ECMAScript data types are divided into two types: 1. Basic data types, including String, Number, Boolean, undefined, null and Symbol types; 2. Reference data types, including Object, Function and Array types.
The operating environment of this tutorial: Windows 7 system, ECMAScript version 6, Dell G3 computer.
ECMAScript data types can be divided into two types: basic data types and reference data types
Basic types
Basic types are also called value types.
String: Any string
Number: Any number
Boolean: true, false
## undefined: undefined
null: null
Symbol
##Object TypeObject type is also called reference type
How to determine the type of datatypeof: can determine undefined, numerical value, string, Boolean value, function
cannot determine : null and Object, Object and Array
Returns the string expression of the data type. instanceof: Determine the specific type of the object.
===: Can judge undefined and null
var a;
console.log(a);//undefined
console.log(typeof a);//"undefined"
console.log(a===undefined);//true
a=4;
console.log(typeof a==="number");//true
a='dewferf';
console.log(typeof a==='string');//true
console.log(typeof a==='String');//false
a=true;
console.log(typeof a === 'boolean');//true
a=null;
console.log(typeof a,a===null);//"object",true
var b1={
b2:[1,'avc',console.log],
b3:function(){
console.log('b3');
return function(){
return 'lxyxxx';
}
}
};
console.log(typeof b1.b2);//'object'
console.log(b1 instanceof Object,b1 instanceof Array);//true,false
console.log(b1.b2 instanceof Array,b1.b2 instanceof Object);//true,true
console.log(b1.b3 instanceof Function,b1.b3 instanceof Object);//true,true
console.log(typeof b1.b3);//'function'
console.log(typeof b1.b3 === 'function');//true
console.log(typeof b1.b2[2]);//'function'
console.log(typeof b1.b2[2] === 'function');//true
b1.b2[2](4);//因为b1.b2[2]是函数,所以会执行
b1.b3()();//
Symbol is a new data type introduced in ECMAScript6, which represents a unique value. Symbol type The value needs to be generated using the Symbol() function, as shown in the following example:
var str = "123"; var sym1 = Symbol(str); var sym2 = Symbol(str); console.log(sym1); // 输出 Symbol(123) console.log(sym2); // 输出 Symbol(123) console.log(sym1 == sym2); // 输出 false :虽然 sym1 与 sym2 看起来是相同的,但实际上它们并不一样,根据 Symbol 类型的特点,sym1 和 sym2 都是独一无二的
Since Symbol values are not objects, properties cannot be added. Basically, it is a string-like data type.javascript learning tutorial[Related recommendations:
The above is the detailed content of What data types does ECMAScript have?. For more information, please follow other related articles on the PHP Chinese website!