DEV Community

Discussion on: Enough JavaScript to get you Started : #13 OOP in JS Practical Guide 👩‍💻👨‍💻

Collapse
 
lathifahdhiya profile image
Lathifahdhiya

So in Java you can only have one class in each file. Is that apply to Javascript too? Also how to know if a variable/function should be public or private?

Collapse
 
whoadarshpandya profile image
Adarsh Pandya
  1. In java it's not compulsory to have one class in each file , rather it's a convetion java devs uses for SoC (separation of concern) .

  2. Same applies in JS one or more class can be defined in one file, as you can see in the example i gave in inheritance I've 2 classes in same file.

  3. Variables/Function which are public can be accessed inside as well as outside class, private members can not be accessed outside class. according to ES2015 syntax it's compulsory to prefix variable or method with '#' to make it private (which is visible difference)

Wish you all the very best for your coding career ahead :)