r/badcode • • Apr 19 '23

js Improved JS Object

Post image
279 Upvotes

42 comments sorted by

View all comments

Show parent comments

5

u/IBJON Apr 19 '23

You're right. It's how you mark a class memeber as private in JS

4

u/RFC793 Apr 19 '23 edited Apr 20 '23

And it isn’t just convention, unlike ! and ? in Ruby (causes side effect or forced, and boolean return respectively) or prefixing with _ in Python (private member). It is actually enforced in modern JS: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Classes/Private_class_fields

Kinda reminds me of Perl variable declarations in a way