Home >Web Front-end >JS Tutorial >What are the data types that are not part of javascript?
The data type that does not belong to javascript is interface, which is a reserved word in js; and the data types of javascript include Undefined, Number, Symbol, etc.
The operating environment of this article: windows7 system, javascript version 1.8.5, Dell G3 computer.
The basic data types of JavaScript are: (1) Undefined, (2) Null, (3) Boolean, (4) String, (5) Number, (6) Symbol, ( 7) Object. ES6 adds the Symbol type. The following mainly talks about some related knowledge points of the Symbol type.
Characteristics of Symbol
1. The instance is unique and unchangeable; a unique identifier The symbol can be used as the unique attribute name of the object so that others will not overwrite or overwrite the attribute value you set.
1 let id = Symbol("id");
2. Characteristics of data types: uniqueness, even if the values generated by the same variable are not equal.
1 let id1 = Symbol("id");2 let id2 = Symbol("id");3 console.log(id1 == id2); //false
3. Characteristics of data types: Hiddenness, for···in, object.keys() cannot be accessed.
1 let id = Symbol("id");2 let obj = {3 [id] : 'symbol' 4 }5 for ( let key in obj){6 console.log(obj[key]); //输出为空7 }
Accessible methods: Object.getOwnPropertySymbols, will return an array whose members are all functions of the current object Symbol value of the attribute name.
1 let id = Symbol("id");2 let obj = {3 [id] : 'symbol' 4 }5 let arr = Object.getOwnPropertySymbols(obj);6 console.log(arr) // [Symbol(id)]7 console.log(obj[arr[0]]) // 'symbol'
4. The same symbol value can be used multiple times. The official provides a global registration and registration method: Symbol.for()
let name1 = Symbol.for("name"); // 检测未创建后新建let name2 = Symbol.for("name"); // 检测已创建后返回console.log(name1 == name2); // true
In this way, you can get the global symbol object through the parameter value. On the contrary, you can use Symbol.keyFor()Get the parameter value.
let name1 = Symbol.for("name"); let name2 = Symbol.for("name"); console.log(Symbol.keyFor("name1")); // 'name'console.log(Symbol.keyFor("name2")); // 'name'
5. The result of instanceof is false
let s = Symbol('foo'); console.log(s instanceof Symbol); // false
Note: The parameters when creating symbol type data are just Used as an identifier, so Symbol() can also be used as a parameter.
[Recommended learning: javascript advanced tutorial]
The above is the detailed content of What are the data types that are not part of javascript?. For more information, please follow other related articles on the PHP Chinese website!