DEV Community

Discussion on: JavaScript v TypeScript

Collapse
 
pranavbaburaj profile image
Pranav Baburaj

No public or private keywords
Hey, I think you have mistaken.
The private keyword is used to hide a method or a property in a class from. To do this in js, you can use

class Hello {
    _private_function(){}
}
Enter fullscreen mode Exit fullscreen mode
Collapse
 
javacode7 profile image
JavaCode7

Ok...

Collapse
 
pranavbaburaj profile image
Pranav Baburaj

:slight_smile:

Thread Thread
 
javacode7 profile image
JavaCode7

I think you mean 😊

Collapse
 
peerreynders profile image
Collapse
 
kwiat1990 profile image
Mateusz Kwiatkowski

Regarding new proposal: why to use # instead of private keyword for the private members? Or am I missing something here?

Thread Thread
 
peerreynders profile image
peerreynders

FAQ:

This sort of declaration is what other languages use (notably Java), and implies that access would be done with this.x. Assuming that isn't the case (see below), in JavaScript this would silently create or access a public field, rather than throwing an error. This is a major potential source of bugs or invisibly making public fields which were intended to be private