Eval() is not working in LWC Javascript, although it is working fine in LWC playground

71 views Asked by At

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:

LWC Javascript Error

0

There are 0 answers