Variables declared with let can only be reassigned by code below the
declaration. The assignment will crash with a ReferenceError if you assign to
the variable.
function getNumberOfChocolates() { return 3; }
let shouldEatChocolates = true;
if (shouldEatChocolates) {
chocolates = 0;
}
let chocolates = getNumberOfChocolates();
To fix this error, move the declaration above the assignment:
function getNumberOfChocolates() { return 3; }
let shouldEatChocolates = true;
let chocolates = getNumberOfChocolates();
if (shouldEatChocolates) {
chocolates = 0;
}
You cannot reassign variables declared with const, and you cannot reference a
variable declared with const above its declaration. The assignment will crash
with a ReferenceError if you run the code.
let timeElapsed = 31;
let pie = "cooking";
if (timeElapsed > 30) {
pi = "cooked";
}
const pi = 3.14;
To fix this error, assign to a different variable or declare a new variable with
a different name:
let timeElapsed = 31;
let pie = "cooking";
if (timeElapsed > 30) {
pie = "cooked";
}
const pi = 3.14;
export function let() {
console.log("access permitted");
}
To fix this error, name the function something other than let, or declare the
function separately with a different name and use export-as:
export function allow() {
console.log("access permitted");
}
function allowAccess() {
console.log("access permitted");
}
export { allowAccess as let };
A function or variable name includes a Unicode escape sequence, and the escape sequence
refers to a character which isn't allowed in a function or variable name:
let guitar\u2604 = "\uD83C\uDFB8";
let handc\uffed = true;
To fix this error, use the code point of a Unicode character which is allowed,
or remove the extraneous backslash from the name:
let guitar\u3604 = "\uD83C\uDFB8";
let handcuffed = true;
The initial character in a function or variable name can be any of the
following:
ID_Start
$
_
Characters after the initial character in a function or variable name can be
any of the following:
The left-hand side of => must be a list of parameters. It is a syntax error if
the left-hand side is instead an expression (such as a property access or a
function call):
if (this.mapSize => this.capacity) {
throw new Error("too many items");
}
let fs = require("fs");
let path = process.argv[2];
fs.mkdir(path () => console.log("done"));
To fix this error, replace => with the intended operator, such as >=:
if (this.mapSize >= this.capacity) {
throw new Error("too many items");
}
Alternatively, make the left-hand side of => valid by adding an operator
(usually ,) before the parameter list:
let fs = require("fs");
let path = process.argv[2];
fs.mkdir(path, () => console.log("done"));