JavaScript Day 21 — Mastering JavaScript Basics: A Comprehensive Guide for Interview Preparation
100 Days of JavaScript Interview Prep: A Beginner’s Journey

Welcome to Day 21–100 Days of JavaScript Interview Prep: A Beginner’s Journey
Embarking on a 100-day adventure focused on learning, practice, and growth sounds like an incredibly rewarding journey.
DAY 21 (April 12th, 2024) — ES6 Classes Part-3 Interview Questions ?
Note — Most important interview question
Question — How to define Private static fields and explain with example?
Answer :
Private static fields -
- It added to the class constructor at class evaluation time, and
- It only available on the class itself.
How to define Private Static Fields
We can define private static field with static keyword and below are few examples
static #test =’test’
static myaddress = ‘test’
Static fields are properties which only belongs to the class.
class MyCard {
static #address = 'test address'; // static field
}
console.log(MyCard.#address);
// accessing static field directly through the class without creating instanceStatic field can directly access through the class without creating the instance.
Whereas Method (normal) we can only access after creating the instance.
class MyCard {
static #address = 'test address'; // static field
getDetail(){ // normal method
return "this is my normal function which will work after creating instance"
}
}
console.log(MyCard.#address);
// accessing static field directly through the class without creating instance
const card = new MyCard();
card.getDetail(); // can access only after creating instance

Tomorrow we will combine the above example to understand the Private Static method and how we can access.
Lastly, Advantage - Static Field are useful for storing data or configuration settings.
Go always slow with Classes Concept — :)
Happy Coding and Stay Tuned :)
Kind is cool !!!
Share knowledge to gain knowledge !!!!
Be kind and treat people with respect !!
If you find my blog helpful, then please subscribe, claps and follow to support :)






