Reflect.apply() JavaScript JS

The JavaScript Reflect.apply() method calls a function using the specified argument.

Note: If the target function is not callable then it will throw TypeError.

Syntax:

Reflect.apply(target, thisArg, arguments)

Parameters:
target: It represents the object that has to be invoked.
thisArg: It will act as this keyword for the function.
arguments: It represents the parameters for the function.

Return:
Result of invoked function.

Example 1:

<!DOCTYPE html>
<html>
<body>
<script>
var n = [100, 200, 5, 40];
document.write(Reflect.apply(Math.max, undefined, n));
</script>
</body>
</html>

Example 2:

<!DOCTYPE html>
<html>
<body>
<script>
document.write(Reflect.apply(Math.floor, undefined, [11.45]));
document.write("</br>");
document.write(Reflect.apply(String.fromCharCode, undefined, [458, 458, 141]));
document.write("</br>");
document.write(Reflect.apply(RegExp.prototype.exec, /od/, ['w3schools']).index);
document.write("</br>");
document.write(Reflect.apply(''.charAt, 'w3schools', [3]));
</script>
</body>
</html>