A JavaScript function is a block of code designed to perform a particular task. These are some of the examples that i have done and compiled. A JavaScript function is a block of code designed to perform a particular task. A JavaScript function is executed when "something" invokes it (calls it).
For Example: function myFunction(p1, p2) { return p1 * p2; // The function returns the product of p1 and p2 }
A function is defined by a keyword "function",followed by a name, followed by (). The parentheses may include parameter names separated by commas: (parameter1, parameter2, ...) The code to be executed, by the function, is placed inside curly brackets: {} e.g. function name(parameter1, parameter2, parameter3) { code to be executed }
Another to consider here is JavaScript RegExp. A regular expression is an object that describes a pattern of characters.
Regular expressions are used to perform pattern-matching and "search-and-replace" functions on text.
For more examples of RegExp refer to this https://www.w3schools.com/jsref/jsref_obj_regexp.asp