What is the difference between RegExp('hi') and new RegExp('hi')?
Does the new keyword do anything here?
What is the difference between RegExp('hi') and new RegExp('hi')?
Does the new keyword do anything here?
It is identical
The
RegExpconstructor is the%RegExp%intrinsic object and the initial value of theRegExpproperty of the global object. WhenRegExpis called as a function rather than as a constructor, it creates and initializes a newRegExpobject. Thus the function callRegExp(…)is equivalent to the object creation expressionnew RegExp(…)with the same arguments.
From http://www.ecma-international.org/ecma-262/6.0/#sec-regexp-constructor