I tried running this code in the LWC playground and it runs fine for me
When I try to run the same code inside a method in LWC component in salesforce (JavaScript), it's throwing an error.
import {
LightningElement
} from 'lwc';
export default class InputText extends LightningElement {
handleCommit(event) {
var value = event.target.value
console.log("Value: " + value);
let validationRule = 'A.length > 5';
console.log("Validation Rule: " + validationRule);
let n = validationRule.replace('A', 'value');
console.log("N: " + n);
let x = eval(n);
console.log("X: " + x);
}
}
<lightning-input type="text" label="Enter some text" oncommit={handleCommit}></lightning-input>
ERROR:

console.log("N: " + n);show in the two environments?