Underscore.js _.isRegExp() Function (original) (raw)
Last Updated : 25 Nov, 2021
_.isRegExp() function:
- It finds whether the object passed is a regular expression or not.
- If the object is a regular expression then it returns true otherwise false.
- We can even apply operations like addition etc on the variables in which the result of _.isRegExp() is stored.
Syntax:
_.isRegExp(object)
Parameters: It takes only one argument which is the object that needs to be checked.
Return value: It returns true if the object passed is a regular expression and if not then false is returned.
Examples:
- Passing a regular expression to the _.isRegExp() function: The _.isRegExp() function takes the element from it’s parameter and starts checking if it is a regular expression or not. Since the object starts and ends with ‘/’, therefore it is a regular expression. Hence, the result is true.
Output: - Passing a string to the -.isRegExp() function: In this we are passing a string to the _.isRegExp() and this can be identified as the parameter passed is inside the ‘ ‘ (quotes). Since a string is not a regular expression therefore, the output will be false.
Output: - Passing a string with ‘/’ to _.isRegExp() function: The _.isRegExp() function takes the parameter which in this case is inside ‘ ‘, hence it is a string. Therefore, all the letters, symbols inside ‘ ‘ will behave as a string character. Hence the overall object is a string. Therefore, the output is false.
Output: - Applying addition operation on the _.isRegExp() function’s output:
In this we are storing the result of both the example 1 and 2 in the variables ‘a’ and ‘b’. Then we are applying addition operation on both the ‘a’ and ‘b’ variables. Since ‘a’ is true and ‘b’ is false, therefore, the addition of true and false will result in 1 which is then stored in ‘c’ variable.
Output:
NOTE: These commands will not work in Google console or in firefox as for these additional files need to be added which they didn’t have added. So, add the given links to your HTML file and then run them. The links are as follows:
Similar Reads
- Underscore.js _.isEmpty() Function Underscore.js _.isEmpty() function is used to check whether a list, array, string, object, etc is empty or not. It first finds out the length of the passed argument and then decides. If the length is zero, then the output is true otherwise false. Syntax:Â _.isEmpty(object);Parameters:It takes only on 3 min read
- Underscore.js _.isMap() Function Underscore.js is a library in javascript that makes operations on arrays, string, objects much easier and handy. _.isMap() function is used to check whether the given object is javascript Map or not. Note: It is very necessary to link the underscore CDN before going and using underscore functions in 2 min read
- Underscore.js _.isSet() Function Underscore.js is a library in javascript that makes operations on arrays, string, objects much easier and handy. _.isSet() function is used to check whether the given object is javascript set or not. When linking the underscore.js CDN The "_" is attached to the browser as global variable. Syntax: _. 2 min read
- Underscore.js _.isString() Function The _.isString() function is used to check whether the given object element is string or not. Syntax: _.isString( object ) Parameters: This function accepts single parameter as mentioned above and described below: object: It contains the value of object that need to be check whether it is an string 1 min read
- Underscore.js _.isDate() function Underscore.js is a javascript library that is capable enough to handle arrays, strings, objects, map, set very easily and efficiently. The _.isDate() function in underscore.js is used to tell if the given object is a date object or not. Syntax: _.isDate(object); Parameters: It takes only one paramet 1 min read
- Underscore.js _.iteratee() Function Underscore.js is a JavaScript library that provides a lot of useful functions that help in the programming in a big way like the map, filter, invoke, etc. even without using any built-in objects. The _.iteratee() function is an inbuilt function in Underscore which is used to generate a callback that 2 min read
- Underscore.js _.isElement() Function The _.isElement() function: is used to check whether the element is a document object model or not. A document object model is the way javascript sees the data of the containing pages. The Cascading style sheet (CSS) and javascript (JS) interact with Document object model (DOM). Syntax:_.isElement(o 3 min read
- Underscore.js _.isArguments() Function The _.isArguments() function is used to check whether the given object is an argument or not. It returns a Boolean value True if the given object is an argument and False otherwise. Syntax: _.isArguments( object ) Parameters: This function accepts one parameter as mentioned above and described below 1 min read
- Underscore.js _.isWeakMap() Function Underscore.js is a library in javascript that makes operations on arrays, string, objects much easier and handy. _.isWeakMap() function is used to check whether the given object is javascript weakmap or not. When linking the underscore.js CDN The "_" is attached to the browser as global variable. Sy 2 min read
- Underscore.js _.isWeakSet() Function Underscore.js is a JavaScript library that makes operations on arrays, string, objects much easier and handy. he _.isWeakSet() function is used to check whether the given object is JavaScript weakset or not. When linking the underscore.js CDN, the "_" is attached to the browser as global variable. S 2 min read