Please check out my code incrementer I recently developed code that can run as a function parameter but I'm not quite sure how vulnerable it is to hacks and/or cheats.
Also, is there anything I could improve?


const h1 = document.getElementById('hi')

world = "world";

function testCode(codeEntered) {
    var code = codeEntered;
  var run = code *= 1;
  return(run);
}
&lt;button onclick="testCode(h1.textContent = world)"&gt;
Test
&lt;/button&gt;

&lt;h1 id="hi"&gt;
Hello
&lt;/h1&gt;
Some thoughts:

Writing testCode(h1.textContent = world) is a bit unconventional, and might not do what you expect: this is the same as writing the two lines
h1.textContent = world;
testCode(world);

because the assignment (the first line) evaluates to the value of the right hand side.

Instead of writing var code = codeEntered;, you can save yourself a line and just use the variable codeEntered instead of making a new variable.

The line  var run = code *= 1; also is a bit unexpected. This is equivalent to writing
code = code * 1;
var run = code;

But code is a string, and multiplying it by 1 evaluates to NaN (try it!), so after that line, code == run == NaN.

Code style: return(run); would typically be written return run; instead (it's not a function).

In summary, testCode actually always returns NaN, but the value then gets thrown away because it isn't used anywhere. In effect, your code actually just runs h1.textContent = world when you click the button, then runs testCode whose value isn't used (but is always NaN anyway).


I hope this gives you some useful feedback.