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?
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) .
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.
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 :)
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
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?
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) .
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.
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 :)