Science Knowings: JavaScript Course For Social Media

Reflect API

Reflect API: Unveiling Hidden JavaScript Powers

Welcome back! After exploring Proxy Objects, let's dive into Reflect API, another powerful tool in JavaScript that gives us deep insights into object behavior.

What is Reflect API?

The Reflect API is a set of built-in functions that allow us to perform operations on objects in a more reflective manner. It provides a unified and consistent way to interact with different object types.

Why Reflect API?

The Reflect API offers several benefits:

  • It allows us to intercept and modify the behavior of built-in object methods.
  • It provides greater control and flexibility when working with objects.
  • It enables metaprogramming, allowing us to write code that manipulates other code.

Methods Provided by Reflect API

The Reflect API offers a comprehensive set of methods, including:

  • Reflect.apply
  • Reflect.construct
  • Reflect.defineProperty
  • Reflect.deleteProperty
  • Reflect.get
  • Reflect.getOwnPropertyDescriptor
  • Reflect.getPrototypeOf


Reflect.apply(func, thisArg, args): Invokes the func function with the specified this and arguments.


Reflect.construct(func, args): Creates and initializes a new object by invoking the func function with the specified arguments.


Reflect.defineProperty(obj, prop, desc): Adds the property prop to obj with the provided desc (property descriptor).


Reflect.deleteProperty(obj, prop): Deletes the property prop from obj.


Reflect.get(obj, prop, receiver): Gets the value of the property prop from obj.


Reflect.getOwnPropertyDescriptor(obj, prop): Gets the property descriptor for the property prop of obj.


Reflect.getPrototypeOf(obj): Gets the prototype of the obj.


Reflect.has(obj, prop): Checks if obj has a property prop.


Reflect.isExtensible(obj): Checks if obj is extensible (can have new properties added).


Reflect.ownKeys(obj): Returns an array of the own property keys of obj.


Reflect.preventExtensions(obj): Prevents obj from being extended (no new properties can be added).


Reflect.set(obj, prop, value, receiver): Sets the value of the property prop in obj.


Reflect.setPrototypeOf(obj, proto): Sets the prototype of obj to proto.

Next Topic: Set Object

In the next session, we'll explore Set objects, data structures that store unique values. They're useful for removing duplicates and performing set operations like unions and intersections. Follow us for more JavaScript adventures!