In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-22 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly introduces what symbol refers to in es6. It is very detailed and has certain reference value. Friends who are interested must finish reading it.
Symbol in es6 is a new primitive data type used to represent unique values, and the greatest use is to define the unique attribute name of an object; because Symbol is a primitive data type, not an object, the Symbol function stack cannot use the new command.
This tutorial operating environment: windows10 system, ECMAScript version 6. 0, Dell G3 computer.
What is symbol in es6
ES6 introduces a new primitive data type, Symbol, which represents a unique value, and the greatest use is to define the unique property name of the object.
The ES6 data type adds Symbol in addition to Number, String, Boolean, Object, null, and undefined.
Basic usage
The Symbol function stack cannot use the new command because Symbol is a primitive data type, not an object. You can take a string as a parameter to provide a description for the newly created Symbol, which can be displayed on the console or used as a string for easy distinction.
Let sy = Symbol ("KK"); console.log (sy); / / Symbol (KK) typeof (sy); / / "symbol" / / the values returned by the same parameter Symbol () are not equal let sy1 = Symbol ("kk"); sy = = sy1; / / false
Parameter characteristics
The parameters of Symbol usually hold a string to identify different values. If the parameter of Symbol is an object, the toString method of that object is called, converted to a string, and then a symbol value is generated.
Var S1 = Symbol ('id1'); var S2 = Symbol (' id1'); console.log (S1 = = S2); / / falsevar S3 = Symbol ({}); console.log (S3); / / Symbol ([object Object])
The parameters in Symbol represent the description of the current symbol value, and even if the parameters are the same, the two symbol values will not be the same.
Usage and characteristics
Symbol cannot be used as an object property name. Operator, use square brackets. Because。 Operator is followed by a string, so you get the string sy property instead of the Symbol value sy property.
Let syObject = {}; syObject [sy] = "kk"; syObject [sy]; / / "kk" syObject.sy; / / undefined is all the contents of this article "what does symbol in es6 refer to?" Thank you for reading! Hope to share the content to help you, more related knowledge, welcome to follow the industry information channel!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.