- Using a constructor for creating an object:
- Using literal notations for creating an object:
- Array: We can store several elements having similar characteristics under a single name by using an array.
- Using constructor for creating a RegExp:
- Using pattern enclosed b/w forward slashes for creating a RegExp:
1. Object example:
Explanation: We have defined an object named student in the above program and printed the values of the keys firstName and the lastName in the console window.
2. Array example:
Explanation: We have created three different arrays, the first with no arguments (empty array), the second array with a single argument (defining number of elements), and the third array with multiple values (four arguments) in the array.
3. RegExp example:
Explanation: We have created a RegExp variable regexp with scale pattern/string and i as the modifier that represents case insensitive matching. When we compare this pattern with the string scaler using the match() method, we get the result string that we have printed on the HTML output page.