Can js throw be followed by a string?

function getRectArea(width, height) {
  if (isNaN(width) || isNaN(height)) {
    throw "err"
  }
}
try {
  getRectArea(3, "A")
} catch (e) {
  console.log(e)
}

when I use such a piece of code, I will report an error: Expected an object to be thrown;
I have no problem executing this code in the console, and the above error will occur in the editor. I don"t know what the problem is and whether it is caused by my eslint configuration.

Mar.23,2021
If you have any problems with

, you can first query the api document. throw statement
throw supports strings, numbers, Boolean values, and objects.
Expected an object to be thrown translates into Chinese that an object is expected to be thrown. Eslint configuration problem


@ onlookers is indeed an eslint configuration problem. Add "no-throw-literal": 0 to the rules object in the eslint configuration and you can

.
Menu