Javascript Regex Constructor Properties

JavaScript regex properties help to return the function and its prototype using regex fields and values. It is used to create the function of the object's prototype. The constructor properties return the various references for JavaScript types:

  • Regular Expression: The constructor property gets the output "function RegExp() { [native code] }" for regex.
  • Numbers: The constructor property gets the output "function Number() { [native code] }"for input numbers.
  • Strings: The constructor property gets the output "function String() { [native code] }"for input strings.
  • Array: The constructor property gets the output "function Array() { [native code] }"for input strings.
  • Boolean: The constructor property gets the output "function Boolean() { [native code] }"for input strings.

Syntax

The following syntax is used to get the object prototype.

Description:

  • The " constructor " keyword shows the output type, such as Number, String, and Array.
  • The output shows in the format of "function output_type() {[native code]}".

Supported Browsers

The browsers supported by the RegExp constructor are listed below:

  • Google Chrome version 1 and later
  • Edge version 12 and later
  • Firefox version 1 and later
  • Internet Explorer 4 and later
  • Opera 5 and later
  • Safari 1 and later

The following examples work for the types of regex data and its value.

Example 1:

The example shows the regex native code for the constructor property. Here, we use regex directly with the constructor keyword.

Output:

The output shows the native code of the object function.

Javascript Regex Constructor Properties

Example 2:

The example shows the array function native code for the constructor property. Here, we use regex value with match using the constructor keyword.

Output:

The output shows the native code of the object function.

Javascript Regex Constructor Properties

Example 3:

The example shows the string native code for the constructor property. Here, we use the regex replace method with the constructor keyword.

Output:

The output shows the native code of the object function.

Javascript Regex Constructor Properties

Example 4:

The example shows the number function native code for the constructor property. Here, we use the regex value with a constructor keyword search.

Output:

The output shows the native code of the object function.

Javascript Regex Constructor Properties

Example 5:

The example shows the Boolean native code for the constructor property. Here, we use the regex test method with the constructor keyword.

Output:

The output shows the native code of the object function.

Javascript Regex Constructor Properties

Conclusion

The constructor property shows the native code for the types of output. We can use multiple methods and modifiers for operation and get the output type of the code.






Latest Courses