Skip to main content

Command Palette

Search for a command to run...

๐Ÿ“š JavaScript Objects and Their Accessibility Methods

Published
โ€ข2 min readโ€ขView as Markdown
๐Ÿ“š JavaScript Objects and Their Accessibility Methods
Z

๐Ÿง Are you facing challenges like slow website performance, poor user experience, cross-browser issues, and difficulty integrating with back-end systems, all while trying to manage business growth without a streamlined digital solution? ๐Ÿค” Are you struggling to reach a wider audience, improve customer engagement, and stay competitive without a web app, while dealing with inefficient operations, limited scalability, and missed revenue opportunities? ๐Ÿš€ Build a web app to expand reach, improve engagement, and streamline operations for growth. โš™๏ธ Optimize performance, enhance user experience, and integrate systems with a smooth, scalable solution. ๐Ÿ‘จโ€๐Ÿ’ป I am Zia-Ur-Rehman a MERN Developer with experience in building scalable and high-performing web applications that solve buisness Problems. I worked with the startup to Help their clients by developing highly scalable webApps to make their global buisness mangable with one click across globe. โœ… Frontend Development to create responsive, user-friendly interfaces that solve the problems of your audience. โœ… Figma to Next.js Functional App transforming your designs into interactive, high-performance Web apps. โœ… Web App Development to expand your reach and improve customer engagement.โœ… Performance Optimization for faster load times and seamless user experience.โœ… Cross-Browser Compatibility ensuring your app works perfectly everywhere.โœ… Backend Integration to streamline operations and boost business efficiency.
If you have an idea that will capture market share, why are you waiting? ๐Ÿš€ DM me today or email me (emailtozia0@gmail.com) and get started!

๐ŸŒŸ What is an Object?

  • An object in JavaScript is a collection of key-value pairs.

  • Keys are strings (or Symbols).

  • Values can be any data type, including functions.

const user = {
  name: 'Alice',
  age: 30,
  greet() {
    console.log(`Hello, I'm ${this.name}`);
  }
};

๐Ÿ”Ž Accessing Object Properties

1. Dot Notation (Traditional Way)

console.log(user.name); // 'Alice'

Simple โœ”๏ธ Readable โœ”๏ธ Fails for dynamic keys โŒ


2. Bracket Notation (Flexible Way)

console.log(user['age']); // 30

Dynamic Access โœ”๏ธ Special Characters โœ”๏ธ Less readable if overused โŒ

Best Practice:

const key = 'name';
console.log(user[key]); // 'Alice'

๐Ÿ“œ Checking Property Existence

1. Using in Operator (Traditional)

console.log('age' in user); // true

2. Using hasOwnProperty() (Best Practice)

console.log(user.hasOwnProperty('age')); // true

Prefer hasOwnProperty() to avoid prototype pollution.


๐Ÿ› ๏ธ Accessing Object Methods

Traditional Way

user.greet();

Modern Safe Call

user.greet?.();

Optional Chaining prevents errors if method is undefined.


๐Ÿ›‚ Iterating Over Objects

1. For...in Loop (Old Way)

for (let key in user) {
  console.log(`${key}: ${user[key]}`);
}

Needs hasOwnProperty() check to avoid inherited properties.


2. Object.keys() + forEach() (Modern)

Object.keys(user).forEach(key => {
  console.log(`${key}: ${user[key]}`);
});

Optimized Iteration

for (const [key, value] of Object.entries(user)) {
  console.log(`${key}: ${value}`);
}

๐Ÿ”ฅ Pro Tip: Destructuring

const { name, age } = user;
console.log(name, age);
  • Improves readability

  • Reduces redundancy


๐Ÿง Knowledge Bombs!

ConceptTraditionalBest Practice
Property AccessDot/Bracket NotationDot for static, Bracket for dynamic keys
Existence Checkin OperatorhasOwnProperty()
Method InvocationDirect callOptional Chaining ?.()
Iterationfor...inObject.entries() + for...of

๐ŸŒŸ Summary

  • Use Dot Notation for known keys.

  • Use Bracket Notation for dynamic keys.

  • Use hasOwnProperty() for safe checks.

  • Use Optional Chaining for method calls.

  • Iterate smartly with Object.entries().

  • Destructure for cleaner code.