this question is different because the first function errors, but the other identical functions work fine.
Question: Why does the first function fail, but not the second? ...in these JS
Regex
functions, from a 3rd party lib used toparse float/ints
etc with the help of the regex function.
Please advise how do I troubleshoot fix this error?
According to https://developer.mozilla.org/en-US/docs/Glossary/Syntax_error
Syntax errors are detected while compiling or parsing source code.
Once the browser encounters a syntax error, it stops parsing the script and reports the error immediately.
You can run these two snippets in DevTools console to see it in action:
const a = text => text.replace(/.*/ g)
const b = text => text.replace(/.*/ g)
// VM744:1 Uncaught SyntaxError: missing ) after argument list
// Only reported the first error on line 1,
// even though the code after isn't valid JavaScript either
const a = text => text.replace(/.*/g)
const b = text => text.replace(/.*/ g)
// VM754:2 Uncaught SyntaxError: missing ) after argument list
// Now that the error is fixed on line 1,
// the parser moved on to find the error on line 2 and reports it
Hope this helps!