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 have 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>

Output:

200

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/, ['w3spoint']).index);
document.write("</br>");
document.write(Reflect.apply(''.charAt, 'w3spoint', [3]));
</script>
</body>
</html>

Output:

11
NJNJ
1
e
Please Share