Reflect API Methods in JavaScript

Level 5251 keystrokes

The Reflect API provides methods for interceptable JavaScript operations in a functional style.

JavaScript code

// Create an object with properties
1const obj = { x: 10, y: 20 };
// Reflect.has checks if property exists
2console.log(Reflect.has(obj, "x"));
// Reflect.get retrieves property value
3console.log(Reflect.get(obj, "y"));
// Reflect.set adds or updates a property
4Reflect.set(obj, "z", 30);
// Reflect.ownKeys returns all own keys: ['x', 'y', 'z']
5console.log(Reflect.ownKeys(obj));
// Reflect.deleteProperty removes a property
6Reflect.deleteProperty(obj, "x");
// Output the modified object
7console.log(obj);
// Check whether the deleted property still exists: false
8console.log(Reflect.has(obj, "x"));

Output

true
20
[ 'x', 'y', 'z' ]
{ y: 20, z: 30 }
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.

  • .× 11
  • (× 11
  • )× 11
  • "× 10
  • ;× 8
  • ,× 7
  • :× 2
  • {× 1
  • }× 1
  • =× 1

More JavaScript examples at level 5

← JavaScript typing practice