Object.hasOwn in JavaScript

Level 3125 keystrokes

Object.hasOwn() checks if an object has a specific property as its own (not inherited).

JavaScript code

// Create an object with two properties
1const obj = { name: "Alice", age: 30 };
// hasOwn returns true for own property "name"
2console.log(Object.hasOwn(obj, "name"));
// hasOwn returns false for inherited "toString" method
3console.log(Object.hasOwn(obj, "toString"));

Output

true
false
Practice typing this code

Practice typing this code. Results are not recorded in the rankings.

Symbols in this code

The symbols you type in this JavaScript code and how often they appear.

  • "× 6
  • .× 4
  • (× 4
  • )× 4
  • ,× 3
  • ;× 3
  • :× 2
  • {× 1
  • }× 1
  • =× 1

More JavaScript examples at level 3

← JavaScript typing practice