menu
techminis

A naukri.com initiative

google-web-stories
Home

>

Programming News

>

JavaScript...
source image

Dev

1M

read

153

img
dot

Image Credit: Dev

JavaScript Static vs Private: Explained by My Cat Oreo

  • Regular Variables/Methods: Oreo's name and color are accessible to everyone.
  • Static Variables/Methods: Oreo does not know about the totalCatCount or whatAreCats() as they are both static, so it is only known by the Cat class.
  • Private Variables/Methods: Oreo's energy level and recoverEnergy() are hidden (private) and can only be accessed using a public method, play().
  • Private Static Variables/Methods: Despite being static, the Cat class can't access the #totalCatNaps or #incrementNapCount(), since they are private static.

Read Full Article

like

9 Likes

For uninterrupted reading, download the app