Nucleus handler tools › Docs › Checks

let and const work like var here

Infolet-const-semanticsA Nucleus check · Worth knowing: it works, with a catch.

Why it matters

Jint 2.x accepts let and const but treats them exactly like var: they belong to the whole function, not the block, and a const can be changed. Code that relies on block scope behaves differently in Nucleus.

Example

✗ Wrong

Game.Play = function () {
  for (let i = 0; i < 2; i++) {
    const name = "p" + i;
  }
};

✓ Right

Game.Play = function () {
  for (var i = 0; i < 2; i++) {
    var name = "p" + i;
  }
};

How to fix it

Use var, so the code says what Nucleus does.

Turn it off, or change how it shows

Each check can be shown as an error, warning, info or hint, or turned off. VS Code: "splitscreenme.lint.rules": { "let-const-semantics": "off" } in your settings. Notepad++: Plugins › Nucleus Co-op handlers › Settings. Command line: ncdev lint --rule let-const-semantics=off. Other editors: the lint.rules setting of ncdev lsp.

Is this right? Tell us what's wrong
Stuck, or not sure? Ask other handler authors: Discordr/nucleuscoop