Sobes.tech
Junior — Middle

What functions are available to all objects in the programming language through the Object class?

sobes.tech AI

Answer from AI

In JavaScript, all objects inherit methods from the Object class prototype. The main functions available to all objects via Object include:

  • toString() — returns a string representation of the object.
  • hasOwnProperty(prop) — checks if the property is an own property (not inherited).
  • isPrototypeOf(obj) — checks if the object exists in the prototype chain of another object.
  • propertyIsEnumerable(prop) — checks if the property is enumerable.
  • valueOf() — returns the primitive value of the object.

Example usage:

const obj = {a: 1};
console.log(obj.toString()); // "[object Object]"
console.log(obj.hasOwnProperty('a')); // true
console.log(obj.hasOwnProperty('b')); // false
What functions are available to all objects in the… - sobes.tech