Skip to content

Commit

Permalink
Be clearer about "direct eval" (mdn#30252)
Browse files Browse the repository at this point in the history
* Attempting to resolve issue mdn#30251

* Update files/en-us/web/javascript/reference/global_objects/eval/index.md

Co-authored-by: Joshua Chen <[email protected]>

---------

Co-authored-by: Joshua Chen <[email protected]>
  • Loading branch information
DanKaplanSES and Josh-Cena authored Nov 15, 2023
1 parent a21ea63 commit 5f92d9c
Showing 1 changed file with 4 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,12 @@ eval(String(expression)); // returns 4

### Direct and indirect eval

There are two modes of `eval()` calls: _direct_ eval and _indirect_ eval. Direct eval only has one form: `eval( )` (the invoked function's name is `eval` and its value is the global `eval` function). Everything else, including invoking it via an aliased variable, via a member access or other expression, or through the optional chaining [`?.`](/en-US/docs/Web/JavaScript/Reference/Operators/Optional_chaining) operator, is indirect.
There are two modes of `eval()` calls: _direct_ eval and _indirect_ eval. Direct eval, as the name implies, refers to _directly_ calling the global `eval` function with `eval(...)`. Everything else, including invoking it via an aliased variable, via a member access or other expression, or through the optional chaining [`?.`](/en-US/docs/Web/JavaScript/Reference/Operators/Optional_chaining) operator, is indirect.

```js
// Direct call
eval("x + y");

// Indirect call using the comma operator to return eval
(0, eval)("x + y");

Expand Down

0 comments on commit 5f92d9c

Please sign in to comment.