![]() |
VOOZH | about |
JavaScript Reflect is a built-in object that gives access to other elements for interceptable operations. This object can be used to check whether an object has a particular property or to change or add new properties to an existing object. This object cannot be explicitly created using the new keyword and we cannot call it a function. Reflect has a set of static functions to perform operations.
Syntax:
Reflect.staticFunc()
Parameters: This object does not have fix parameters, it depends upon the static function being used with it
Return Type: The return values depend on the function being used.
Example 1: This example uses Reflect method to check and add properties in a particular object.
Output:
true
{name: 'Raj', course: 'DSA', website: 'geeksforgeeks.org', Rating: '5'}
Example 2: This example uses Reflect functions to construct a new object.
Output:
true
Details {name: 'Shobhit', course: 'DSA'}
Example 3: This example uses Reflect methods to freeze an array so that new elements cannot be added to it.
Output: Using the preventExtensions method new properties cannot be added to the array. This helps to freeze the array
(4) ['Hello', 'Welcome', 'to', 'GeeksforGeeks'] true (4) ['Hello', 'Welcome', 'to', 'GeeksforGeeks']
Supported Browsers:
We have a complete list of JavaScript Reflect methods, to check please go through the JavaScript Reflect Reference article.