-2

Came across something I cant find in docs. This #selectedIndex = 0; what does # do?

class WcTabPanel extends HTMLElement {
    static observedAttributes = ["selected-index", "direction"];
    #selectedIndex = 0;

appears in this example https://codepen.io/ndesmic/pen/mdELqbM

Peter Moore
  • 1,632
  • 1
  • 17
  • 31
  • 2
    [Private fields](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Classes/Private_class_fields) – kelsny Feb 08 '23 at 20:17
  • You might want to refer to this https://stackoverflow.com/questions/64968964/what-does-the-symbol-do-in-javascript – Bhartesh Kaushik Feb 08 '23 at 20:19
  • See [What does this symbol mean in JavaScript?](/q/9549780/4642212) and the documentation on MDN about [expressions and operators](//developer.mozilla.org/en/docs/Web/JavaScript/Reference/Operators) and [statements](//developer.mozilla.org/en/docs/Web/JavaScript/Reference/Statements). – Sebastian Simon Feb 08 '23 at 20:19

1 Answers1

2

It means private field.

Class fields are public by default, but private class members can be created by using a hash # prefix. The privacy encapsulation of these class features is enforced by JavaScript itself.

You can find documentation here (https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Classes/Private_class_fields).

Anton Marinenko
  • 2,749
  • 1
  • 10
  • 16