Eval() - JavaScript - MDN Web Docs - Mozilla

  • Skip to main content
  • Skip to search
eval() Baseline Widely available

This feature is well established and works across many devices and browser versions. It’s been available across browsers since ⁨July 2015⁩.

  • Learn more
  • See full compatibility
  • Report feedback

Warning: Executing JavaScript from a string is an enormous security risk. It is far too easy for a bad actor to run arbitrary code when you use eval(). See Never use direct eval()!, below.

The eval() function evaluates JavaScript code represented as a string and returns its completion value. The source is parsed as a script.

In this article

  • Try it
  • Syntax
  • Description
  • Examples
  • Specifications
  • Browser compatibility
  • See also

Try it

console.log(eval("2 + 2")); // Expected output: 4 console.log(eval(new String("2 + 2"))); // Expected output: 2 + 2 console.log(eval("2 + 2") === eval("4")); // Expected output: true console.log(eval("2 + 2") === eval(new String("2 + 2"))); // Expected output: false

Syntax

jseval(script)

Parameters

script

A string representing a JavaScript expression, statement, or sequence of statements. The expression can include variables and properties of existing objects. It will be parsed as a script, so import declarations (which can only exist in modules) are not allowed.

Return value

The completion value of evaluating the given code. If the completion value is empty, undefined is returned. If script is not a string primitive, eval() returns the argument unchanged.

Exceptions

Throws any exception that occurs during evaluation of the code, including SyntaxError if script fails to be parsed as a script.

Description

eval() is a function property of the global object.

The argument of the eval() function is a string. It will evaluate the source string as a script body, which means both statements and expressions are allowed. It returns the completion value of the code. For expressions, it's the value the expression evaluates to. Many statements and declarations have completion values as well, but the result may be surprising (for example, the completion value of an assignment is the assigned value, but the completion value of let is undefined), so it's recommended to not rely on statements' completion values.

In strict mode, declaring a variable named eval or re-assigning eval is a SyntaxError.

js"use strict"; const eval = 1; // SyntaxError: Unexpected eval or arguments in strict mode

If the argument of eval() is not a string, eval() returns the argument unchanged. In the following example, passing a String object instead of a primitive causes eval() to return the String object rather than evaluating the string.

jseval(new String("2 + 2")); // returns a String object containing "2 + 2" eval("2 + 2"); // returns 4

To work around the issue in a generic fashion, you can coerce the argument to a string yourself before passing it to eval().

jsconst expression = new String("2 + 2"); eval(String(expression)); // returns 4

Direct and indirect eval

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 ?. operator, is indirect.

js// Direct call eval("x + y"); // Indirect call using the comma operator to return eval (0, eval)("x + y"); // Indirect call through optional chaining eval?.("x + y"); // Indirect call using a variable to store and return eval const myEval = eval; myEval("x + y"); // Indirect call through member access const obj = { eval }; obj.eval("x + y");

Indirect eval can be seen as if the code is evaluated within a separate <script> tag. This means:

  • Indirect eval works in the global scope rather than the local scope, and the code being evaluated doesn't have access to local variables within the scope where it's being called.

    jsfunction test() { const x = 2; const y = 4; // Direct call, uses local scope console.log(eval("x + y")); // Result is 6 // Indirect call, uses global scope console.log(eval?.("x + y")); // Throws because x is not defined in global scope }
  • Indirect eval does not inherit the strictness of the surrounding context, and is only in strict mode if the source string itself has a "use strict" directive.

    jsfunction nonStrictContext() { eval?.(`with (Math) console.log(PI);`); } function strictContext() { "use strict"; eval?.(`with (Math) console.log(PI);`); } function strictContextStrictEval() { "use strict"; eval?.(`"use strict"; with (Math) console.log(PI);`); } nonStrictContext(); // Logs 3.141592653589793 strictContext(); // Logs 3.141592653589793 strictContextStrictEval(); // Uncaught SyntaxError: Strict mode code may not include a with statement

    On the other hand, direct eval inherits the strictness of the invoking context.

    jsfunction nonStrictContext() { eval(`with (Math) console.log(PI);`); } function strictContext() { "use strict"; eval(`with (Math) console.log(PI);`); } function strictContextStrictEval() { "use strict"; eval(`"use strict"; with (Math) console.log(PI);`); } nonStrictContext(); // Logs 3.141592653589793 strictContext(); // Uncaught SyntaxError: Strict mode code may not include a with statement strictContextStrictEval(); // Uncaught SyntaxError: Strict mode code may not include a with statement
  • var-declared variables and function declarations would go into the surrounding scope if the source string is not interpreted in strict mode — for indirect eval, they become global variables. If it's a direct eval in a strict mode context, or if the eval source string itself is in strict mode, then var and function declarations do not "leak" into the surrounding scope.

    js// Neither context nor source string is strict, // so var creates a variable in the surrounding scope eval("var a = 1;"); console.log(a); // 1 // Context is not strict, but eval source is strict, // so b is scoped to the evaluated script eval("'use strict'; var b = 1;"); console.log(b); // ReferenceError: b is not defined function strictContext() { "use strict"; // Context is strict, but this is indirect and the source // string is not strict, so c is still global eval?.("var c = 1;"); // Direct eval in a strict context, so d is scoped eval("var d = 1;"); } strictContext(); console.log(c); // 1 console.log(d); // ReferenceError: d is not defined

    let and const declarations within the evaluated string are always scoped to that script.

  • Direct eval may have access to additional contextual expressions. For example, in a function's body, one can use new.target:

    jsfunction Ctor() { eval("console.log(new.target)"); } new Ctor(); // [Function: Ctor]

Never use direct eval()!

Using direct eval() suffers from multiple problems:

  • eval() executes the code it's passed with the privileges of the caller. If you run eval() with a string that could be affected by a malicious party, you may end up running malicious code on the user's machine with the permissions of your webpage / extension. More importantly, allowing third-party code to access the scope in which eval() was invoked (if it's a direct eval) can lead to possible attacks that reads or changes local variables.
  • eval() is slower than the alternatives, since it has to invoke the JavaScript interpreter, while many other constructs are optimized by modern JS engines.
  • Modern JavaScript interpreters convert JavaScript to machine code. This means that any concept of variable naming gets obliterated. Thus, any use of eval() will force the browser to do long expensive variable name lookups to figure out where the variable exists in the machine code and set its value. Additionally, new things can be introduced to that variable through eval(), such as changing the type of that variable, forcing the browser to re-evaluate all of the generated machine code to compensate.
  • Minifiers give up on any minification if the scope is transitively depended on by eval(), because otherwise eval() cannot read the correct variable at runtime.

There are many cases where the use of eval() or related methods can be optimized or avoided altogether.

Using indirect eval()

Consider this code:

jsfunction looseJsonParse(obj) { return eval(`(${obj})`); } console.log(looseJsonParse("{ a: 4 - 1, b: function () {}, c: new Map() }"));

Simply using indirect eval and forcing strict mode can make the code much better:

jsfunction looseJsonParse(obj) { return eval?.(`"use strict";(${obj})`); } console.log(looseJsonParse("{ a: 4 - 1, b: function () {}, c: new Map() }"));

The two code snippets above may seem to work the same way, but they do not; the first one using direct eval suffers from multiple problems.

  • It is a great deal slower, due to more scope inspections. Notice c: new Map() in the evaluated string. In the indirect eval version, the object is being evaluated in the global scope, so it is safe for the interpreter to assume that Map refers to the global Map() constructor instead of a local variable called Map. However, in the code using direct eval, the interpreter cannot assume this. For example, in the following code, Map in the evaluated string doesn't refer to window.Map().

    jsfunction looseJsonParse(obj) { class Map {} return eval(`(${obj})`); } console.log(looseJsonParse(`{ a: 4 - 1, b: function () {}, c: new Map() }`));

    Thus, in the eval() version of the code, the browser is forced to make the expensive lookup call to check to see if there are any local variables called Map().

  • If not using strict mode, var declarations within the eval() source becomes variables in the surrounding scope. This leads to hard-to-debug issues if the string is acquired from external input, especially if there's an existing variable with the same name.

  • Direct eval can read and mutate bindings in the surrounding scope, which may lead to external input corrupting local data.

  • When using direct eval, especially when the eval source cannot be proven to be in strict mode, the engine — and build tools — have to disable all optimizations related to inlining, because the eval() source can depend on any variable name in its surrounding scope.

However, using indirect eval() does not allow passing extra bindings other than existing global variables for the evaluated source to read. If you need to specify additional variables that the evaluated source should have access to, consider using the Function() constructor.

Using the Function() constructor

The Function() constructor is very similar to the indirect eval example above: it also evaluates the JavaScript source passed to it in the global scope without reading or mutating any local bindings, and therefore allows engines to do more optimizations than direct eval().

The difference between eval() and Function() is that the source string passed to Function() is parsed as a function body, not as a script. There are a few nuances — for example, you can use return statements at the top level of a function body, but not in a script.

The Function() constructor is useful if you wish to create local bindings within your eval source, by passing the variables as parameter bindings.

jsfunction add(a, b) { return a + b; } function runCodeWithAddFunction(obj) { return Function("add", `"use strict";return (${obj});`)(add); } console.log(runCodeWithAddFunction("add(5, 7)")); // 12

Both eval() and Function() implicitly evaluate arbitrary code, and are forbidden in strict CSP settings. There are also additional safer (and faster!) alternatives to eval() or Function() for common use-cases.

Using bracket accessors

You should not use eval() to access properties dynamically. Consider the following example where the property of the object to be accessed is not known until the code is executed. This can be done with eval():

jsconst obj = { a: 20, b: 30 }; const propName = getPropName(); // returns "a" or "b" const result = eval(`obj.${propName}`);

However, eval() is not necessary here — in fact, it's more error-prone, because if propName is not a valid identifier, it leads to a syntax error. Moreover, if getPropName is not a function you control, this may lead to execution of arbitrary code. Instead, use the property accessors, which are much faster and safer:

jsconst obj = { a: 20, b: 30 }; const propName = getPropName(); // returns "a" or "b" const result = obj[propName]; // obj["a"] is the same as obj.a

You can even use this method to access descendant properties. Using eval(), this would look like:

jsconst obj = { a: { b: { c: 0 } } }; const propPath = getPropPath(); // suppose it returns "a.b.c" const result = eval(`obj.${propPath}`); // 0

Avoiding eval() here could be done by splitting the property path and looping through the different properties:

jsfunction getDescendantProp(obj, desc) { const arr = desc.split("."); while (arr.length) { obj = obj[arr.shift()]; } return obj; } const obj = { a: { b: { c: 0 } } }; const propPath = getPropPath(); // suppose it returns "a.b.c" const result = getDescendantProp(obj, propPath); // 0

Setting a property that way works similarly:

jsfunction setDescendantProp(obj, desc, value) { const arr = desc.split("."); while (arr.length > 1) { obj = obj[arr.shift()]; } return (obj[arr[0]] = value); } const obj = { a: { b: { c: 0 } } }; const propPath = getPropPath(); // suppose it returns "a.b.c" const result = setDescendantProp(obj, propPath, 1); // obj.a.b.c is now 1

However, beware that using bracket accessors with unconstrained input is not safe either — it may lead to object injection attacks.

Using callbacks

JavaScript has first-class functions, which means you can pass functions as arguments to other APIs, store them in variables and objects' properties, and so on. Many DOM APIs are designed with this in mind, so you can (and should) write:

js// Instead of setTimeout("…", 1000) use: setTimeout(() => { // … }, 1000); // Instead of elt.setAttribute("onclick", "…") use: elt.addEventListener("click", () => { // … });

Closures are also helpful as a way to create parameterized functions without concatenating strings.

Using JSON

If the string you're calling eval() on contains data (for example, an array: "[1, 2, 3]"), as opposed to code, you should consider switching to JSON, which allows the string to use a subset of JavaScript syntax to represent data.

Note that since JSON syntax is limited compared to JavaScript syntax, many valid JavaScript literals will not parse as JSON. For example, trailing commas are not allowed in JSON, and property names (keys) in object literals must be enclosed in quotes. Be sure to use a JSON serializer to generate strings that will be later parsed as JSON.

Passing carefully constrained data instead of arbitrary code is a good idea in general. For example, an extension designed to scrape contents of web-pages could have the scraping rules defined in XPath instead of JavaScript code.

Examples

Using eval()

In the following code, both of the statements containing eval() return 42. The first evaluates the string "x + y + 1"; the second evaluates the string "42".

jsconst x = 2; const y = 39; const z = "42"; eval("x + y + 1"); // 42 eval(z); // 42

eval() returns the completion value of statements

eval() returns the completion value of statements. For if, it would be the last expression or statement evaluated.

jsconst str = "if (a) { 1 + 1 } else { 1 + 2 }"; let a = true; let b = eval(str); console.log(`b is: ${b}`); // b is: 2 a = false; b = eval(str); console.log(`b is: ${b}`); // b is: 3

The following example uses eval() to evaluate the string str. This string consists of JavaScript statements that assign z a value of 42 if x is five, and assign 0 to z otherwise. When the second statement is executed, eval() will cause these statements to be performed, and it will also evaluate the set of statements and return the value that is assigned to z, because the completion value of an assignment is the assigned value.

jsconst x = 5; const str = `if (x === 5) { console.log("z is 42"); z = 42; } else { z = 0; }`; console.log("z is ", eval(str)); // z is 42 z is 42

If you assign multiple values then the last value is returned.

jslet x = 5; const str = `if (x === 5) { console.log("z is 42"); z = 42; x = 420; } else { z = 0; }`; console.log("x is", eval(str)); // z is 42 x is 420

eval() as a string defining function requires "(" and ")" as prefix and suffix

js// This is a function declaration const fctStr1 = "function a() {}"; // This is a function expression const fctStr2 = "(function b() {})"; const fct1 = eval(fctStr1); // return undefined, but `a` is available as a global function now const fct2 = eval(fctStr2); // return the function `b`

Specifications

Specification
ECMAScript® 2026 Language Specification# sec-eval-x

Browser compatibility

See also

  • Property accessors
  • WebExtensions: Using eval in content scripts

Help improve MDN

Was this page helpful to you? Yes No Learn how to contribute

This page was last modified on ⁨Jul 8, 2025⁩ by MDN contributors.

View this page on GitHub • Report a problem with this content Filter sidebar
  1. JavaScript
  2. Tutorials and guides
  3. JavaScript Guide
    1. Introduction
    2. Grammar and types
    3. Control flow and error handling
    4. Loops and iteration
    5. Functions
    6. Expressions and operators
    7. Numbers and strings
    8. Representing dates & times
    9. Regular expressions
    10. Indexed collections
    11. Keyed collections
    12. Working with objects
    13. Using classes
    14. Using promises
    15. JavaScript typed arrays
    16. Iterators and generators
    17. Resource management
    18. Internationalization
    19. JavaScript modules
  4. Intermediate
    1. Language overview
    2. JavaScript data structures
    3. Equality comparisons and sameness
    4. Enumerability and ownership of properties
    5. Closures
  5. Advanced
    1. Inheritance and the prototype chain
    2. Meta programming
    3. Memory Management
  6. References
  7. Built-in objects
    1. AggregateError
    2. Array
    3. ArrayBuffer
    4. AsyncDisposableStack
    5. AsyncFunction
    6. AsyncGenerator
    7. AsyncGeneratorFunction
    8. AsyncIterator
    9. Atomics
    10. BigInt
    11. BigInt64Array
    12. BigUint64Array
    13. Boolean
    14. DataView
    15. Date
    16. decodeURI()
    17. decodeURIComponent()
    18. DisposableStack
    19. encodeURI()
    20. encodeURIComponent()
    21. Error
    22. escape() Deprecated
    23. eval()
    24. EvalError
    25. FinalizationRegistry
    26. Float16Array
    27. Float32Array
    28. Float64Array
    29. Function
    30. Generator
    31. GeneratorFunction
    32. globalThis
    33. Infinity
    34. Int8Array
    35. Int16Array
    36. Int32Array
    37. InternalError Non-standard
    38. Intl
    39. isFinite()
    40. isNaN()
    41. Iterator
    42. JSON
    43. Map
    44. Math
    45. NaN
    46. Number
    47. Object
    48. parseFloat()
    49. parseInt()
    50. Promise
    51. Proxy
    52. RangeError
    53. ReferenceError
    54. Reflect
    55. RegExp
    56. Set
    57. SharedArrayBuffer
    58. String
    59. SuppressedError
    60. Symbol
    61. SyntaxError
    62. Temporal
    63. TypedArray
    64. TypeError
    65. Uint8Array
    66. Uint8ClampedArray
    67. Uint16Array
    68. Uint32Array
    69. undefined
    70. unescape() Deprecated
    71. URIError
    72. WeakMap
    73. WeakRef
    74. WeakSet
  8. Expressions & operators
    1. Addition (+)
    2. Addition assignment (+=)
    3. Assignment (=)
    4. async function expression
    5. async function* expression
    6. await
    7. Bitwise AND (&)
    8. Bitwise AND assignment (&=)
    9. Bitwise NOT (~)
    10. Bitwise OR (|)
    11. Bitwise OR assignment (|=)
    12. Bitwise XOR (^)
    13. Bitwise XOR assignment (^=)
    14. class expression
    15. Comma operator (,)
    16. Conditional (ternary) operator
    17. Decrement (--)
    18. delete
    19. Destructuring
    20. Division (/)
    21. Division assignment (/=)
    22. Equality (==)
    23. Exponentiation (**)
    24. Exponentiation assignment (**=)
    25. function expression
    26. function* expression
    27. Greater than (>)
    28. Greater than or equal (>=)
    29. Grouping operator ( )
    30. import.meta
      1. import.meta.resolve()
    31. import()
    32. in
    33. Increment (++)
    34. Inequality (!=)
    35. instanceof
    36. Left shift (<<)
    37. Left shift assignment (<<=)
    38. Less than (<)
    39. Less than or equal (<=)
    40. Logical AND (&&)
    41. Logical AND assignment (&&=)
    42. Logical NOT (!)
    43. Logical OR (||)
    44. Logical OR assignment (||=)
    45. Multiplication (*)
    46. Multiplication assignment (*=)
    47. new
    48. new.target
    49. null
    50. Nullish coalescing assignment (??=)
    51. Nullish coalescing operator (??)
    52. Object initializer
    53. Operator precedence
    54. Optional chaining (?.)
    55. Property accessors
    56. Remainder (%)
    57. Remainder assignment (%=)
    58. Right shift (>>)
    59. Right shift assignment (>>=)
    60. Spread syntax (...)
    61. Strict equality (===)
    62. Strict inequality (!==)
    63. Subtraction (-)
    64. Subtraction assignment (-=)
    65. super
    66. this
    67. typeof
    68. Unary negation (-)
    69. Unary plus (+)
    70. Unsigned right shift (>>>)
    71. Unsigned right shift assignment (>>>=)
    72. void operator
    73. yield
    74. yield*
  9. Statements & declarations
    1. async function
    2. async function*
    3. await using
    4. Block statement
    5. break
    6. class
    7. const
    8. continue
    9. debugger
    10. do...while
    11. Empty statement
    12. export
    13. Expression statement
    14. for
    15. for await...of
    16. for...in
    17. for...of
    18. function
    19. function*
    20. if...else
    21. import
      1. Import attributes
    22. Labeled statement
    23. let
    24. return
    25. switch
    26. throw
    27. try...catch
    28. using
    29. var
    30. while
    31. with Deprecated
  10. Functions
    1. Arrow function expressions
    2. Default parameters
    3. get
    4. Method definitions
    5. Rest parameters
    6. set
    7. The arguments object
      1. [Symbol.iterator]()
      2. callee Deprecated
      3. length
  11. Classes
    1. constructor
    2. extends
    3. Private elements
    4. Public class fields
    5. static
    6. Static initialization blocks
  12. Regular expressions
    1. Backreference: \1, \2
    2. Capturing group: (...)
    3. Character class escape: \d, \D, \w, \W, \s, \S
    4. Character class: [...], [^...]
    5. Character escape: \n, \u{...}
    6. Disjunction: |
    7. Input boundary assertion: ^, $
    8. Literal character: a, b
    9. Lookahead assertion: (?=...), (?!...)
    10. Lookbehind assertion: (?<=...), (?<!...)
    11. Modifier: (?ims-ims:...)
    12. Named backreference: \k<name>
    13. Named capturing group: (?<name>...)
    14. Non-capturing group: (?:...)
    15. Quantifier: *, +, ?, {n}, {n,}, {n,m}
    16. Unicode character class escape: \p{...}, \P{...}
    17. Wildcard: .
    18. Word boundary assertion: \b, \B
  13. Errors
    1. AggregateError: No Promise in Promise.any was resolved
    2. Error: Permission denied to access property "x"
    3. InternalError: too much recursion
    4. RangeError: argument is not a valid code point
    5. RangeError: BigInt division by zero
    6. RangeError: BigInt negative exponent
    7. RangeError: form must be one of 'NFC', 'NFD', 'NFKC', or 'NFKD'
    8. RangeError: invalid array length
    9. RangeError: invalid date
    10. RangeError: precision is out of range
    11. RangeError: radix must be an integer
    12. RangeError: repeat count must be less than infinity
    13. RangeError: repeat count must be non-negative
    14. RangeError: x can't be converted to BigInt because it isn't an integer
    15. ReferenceError: "x" is not defined
    16. ReferenceError: assignment to undeclared variable "x"
    17. ReferenceError: can't access lexical declaration 'X' before initialization
    18. ReferenceError: must call super constructor before using 'this' in derived class constructor
    19. ReferenceError: super() called twice in derived class constructor
    20. SyntaxError: 'arguments'/'eval' can't be defined or assigned to in strict mode code
    21. SyntaxError: "0"-prefixed octal literals are deprecated
    22. SyntaxError: "use strict" not allowed in function with non-simple parameters
    23. SyntaxError: "x" is a reserved identifier
    24. SyntaxError: \ at end of pattern
    25. SyntaxError: a declaration in the head of a for-of loop can't have an initializer
    26. SyntaxError: applying the 'delete' operator to an unqualified name is deprecated
    27. SyntaxError: arguments is not valid in fields
    28. SyntaxError: await is only valid in async functions, async generators and modules
    29. SyntaxError: await/yield expression can't be used in parameter
    30. SyntaxError: cannot use `??` unparenthesized within `||` and `&&` expressions
    31. SyntaxError: character class escape cannot be used in class range in regular expression
    32. SyntaxError: continue must be inside loop
    33. SyntaxError: duplicate capture group name in regular expression
    34. SyntaxError: duplicate formal argument x
    35. SyntaxError: for-in loop head declarations may not have initializers
    36. SyntaxError: function statement requires a name
    37. SyntaxError: functions cannot be labelled
    38. SyntaxError: getter and setter for private name #x should either be both static or non-static
    39. SyntaxError: getter functions must have no arguments
    40. SyntaxError: identifier starts immediately after numeric literal
    41. SyntaxError: illegal character
    42. SyntaxError: import declarations may only appear at top level of a module
    43. SyntaxError: incomplete quantifier in regular expression
    44. SyntaxError: invalid assignment left-hand side
    45. SyntaxError: invalid BigInt syntax
    46. SyntaxError: invalid capture group name in regular expression
    47. SyntaxError: invalid character in class in regular expression
    48. SyntaxError: invalid class set operation in regular expression
    49. SyntaxError: invalid decimal escape in regular expression
    50. SyntaxError: invalid identity escape in regular expression
    51. SyntaxError: invalid named capture reference in regular expression
    52. SyntaxError: invalid property name in regular expression
    53. SyntaxError: invalid range in character class
    54. SyntaxError: invalid regexp group
    55. SyntaxError: invalid regular expression flag "x"
    56. SyntaxError: invalid unicode escape in regular expression
    57. SyntaxError: JSON.parse: bad parsing
    58. SyntaxError: label not found
    59. SyntaxError: missing : after property id
    60. SyntaxError: missing ) after argument list
    61. SyntaxError: missing ) after condition
    62. SyntaxError: missing ] after element list
    63. SyntaxError: missing } after function body
    64. SyntaxError: missing } after property list
    65. SyntaxError: missing = in const declaration
    66. SyntaxError: missing formal parameter
    67. SyntaxError: missing name after . operator
    68. SyntaxError: missing variable name
    69. SyntaxError: negated character class with strings in regular expression
    70. SyntaxError: new keyword cannot be used with an optional chain
    71. SyntaxError: nothing to repeat
    72. SyntaxError: numbers out of order in {} quantifier.
    73. SyntaxError: octal escape sequences can't be used in untagged template literals or in strict mode code
    74. SyntaxError: parameter after rest parameter
    75. SyntaxError: private fields can't be deleted
    76. SyntaxError: property name __proto__ appears more than once in object literal
    77. SyntaxError: raw bracket is not allowed in regular expression with unicode flag
    78. SyntaxError: redeclaration of formal parameter "x"
    79. SyntaxError: reference to undeclared private field or method #x
    80. SyntaxError: rest parameter may not have a default
    81. SyntaxError: return not in function
    82. SyntaxError: setter functions must have one argument
    83. SyntaxError: string literal contains an unescaped line break
    84. SyntaxError: super() is only valid in derived class constructors
    85. SyntaxError: tagged template cannot be used with optional chain
    86. SyntaxError: Unexpected '#' used outside of class body
    87. SyntaxError: Unexpected token
    88. SyntaxError: unlabeled break must be inside loop or switch
    89. SyntaxError: unparenthesized unary expression can't appear on the left-hand side of '**'
    90. SyntaxError: use of super property/member accesses only valid within methods or eval code within methods
    91. SyntaxError: Using //@ to indicate sourceURL pragmas is deprecated. Use //# instead
    92. TypeError: 'caller', 'callee', and 'arguments' properties may not be accessed
    93. TypeError: 'x' is not iterable
    94. TypeError: "x" is (not) "y"
    95. TypeError: "x" is not a constructor
    96. TypeError: "x" is not a function
    97. TypeError: "x" is not a non-null object
    98. TypeError: "x" is read-only
    99. TypeError: already executing generator
    100. TypeError: BigInt value can't be serialized in JSON
    101. TypeError: calling a builtin X constructor without new is forbidden
    102. TypeError: can't access/set private field or method: object is not the right class
    103. TypeError: can't assign to property "x" on "y": not an object
    104. TypeError: can't convert BigInt to number
    105. TypeError: can't convert x to BigInt
    106. TypeError: can't define property "x": "obj" is not extensible
    107. TypeError: can't delete non-configurable array element
    108. TypeError: can't redefine non-configurable property "x"
    109. TypeError: can't set prototype of this object
    110. TypeError: can't set prototype: it would cause a prototype chain cycle
    111. TypeError: cannot use 'in' operator to search for 'x' in 'y'
    112. TypeError: class constructors must be invoked with 'new'
    113. TypeError: cyclic object value
    114. TypeError: derived class constructor returned invalid value x
    115. TypeError: getting private setter-only property
    116. TypeError: Initializing an object twice is an error with private fields/methods
    117. TypeError: invalid 'instanceof' operand 'x'
    118. TypeError: invalid Array.prototype.sort argument
    119. TypeError: invalid assignment to const "x"
    120. TypeError: Iterator/AsyncIterator constructor can't be used directly
    121. TypeError: matchAll/replaceAll must be called with a global RegExp
    122. TypeError: More arguments needed
    123. TypeError: null/undefined has no properties
    124. TypeError: property "x" is non-configurable and can't be deleted
    125. TypeError: Reduce of empty array with no initial value
    126. TypeError: setting getter-only property "x"
    127. TypeError: WeakSet key/WeakMap value 'x' must be an object or an unregistered symbol
    128. TypeError: X.prototype.y called on incompatible type
    129. URIError: malformed URI sequence
    130. Warning: -file- is being assigned a //# sourceMappingURL, but already has one
    131. Warning: unreachable code after return statement
  14. Misc
    1. JavaScript technologies overview
    2. Execution model
    3. Lexical grammar
    4. Iteration protocols
    5. Strict mode
    6. Template literals
    7. Trailing commas
    8. Deprecated features

Từ khóa » Hàm Eval Trong Js