0

I was configuring webpack, and I saw something I am very confused about and cannot figure out.

x = {
  test: /\\.css$/
}

console.log(x);
console.log(JSON.stringify(x));

I just don't understand how '/\.css$/' is a valid value, why is it not in quotes? Can someone tell me what is going on here? I suspect it is not a json thing but a javascript thing.. but can someone enlighten me?

Thanks

Duncan
  • 19
  • 4
  • 2
    No, it's not JSON, it's just a JavaScript object. The forward slash begins a regular expression. – elclanrs Nov 29 '20 at 18:26
  • Ah yeah that makes sense, I don't think I really understood the difference. – Duncan Nov 29 '20 at 18:41
  • Duplicate of [Meaning of javascript text between two slashes](https://stackoverflow.com/q/16345748/4642212). See [What does this symbol mean in JavaScript?](https://stackoverflow.com/q/9549780/4642212) and the documentation on MDN about [expressions and operators](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators) and [statements](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements). – Sebastian Simon Nov 29 '20 at 18:44

0 Answers0