avatarKirti K

Summary

The provided web content is a comprehensive guide focusing on mastering JavaScript basics, specifically ES6 Classes, as part of a 100-day JavaScript interview preparation journey aimed at beginners.

Abstract

The content delves into the day 21 of a 100-day JavaScript learning challenge, with an emphasis on understanding ES6 Classes. It addresses an important interview question on defining private static fields and provides examples and explanations on how to declare and access these fields within a class. The article highlights the distinction between static fields, which can be accessed directly through the class, and instance methods, which require an object instance. It also foreshadows the exploration of private static methods in future content. The author, Kirti Kaushal, encourages readers to subscribe and follow for more insightful content, advocating for sharing knowledge and treating people with respect.

Opinions

  • The author considers the understanding of private static fields as a crucial topic for JavaScript interviews.
  • Static fields are presented as advantageous for storing data or configuration settings.
  • The article suggests a methodical and slow-paced approach to grasping the concepts of ES6 Classes.
  • There is an emphasis on kindness and knowledge sharing within the developer community, suggesting these values are important to the author.
  • The author believes in the value of their blog for readers' learning and interview preparation, as indicated by the invitation to subscribe, clap, and follow.

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 instance

Static 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 :)

Es6 Classes Static field -JavaScript Day 21 — Mastering JavaScript Basics: A Comprehensive Guide for Interview Preparation -With kirti kaushal
Coding
Coding Interviews
Front End Development
Javascript Interview
Programming
Recommended from ReadMedium