Underscore.js _.isRegExp() Function Last Updated : 25 Nov, 2021 Comments Improve Suggest changes Like Article Like Report _.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. html <html> <head> <script src = "https://cdnjs.cloudflare.com/ajax/libs/underscore.js/1.9.1/underscore-min.js" > </script> </head> <body> <script type="text/javascript"> console.log(_.isRegExp(/geek/)); </script> </body> </html> 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. html <html> <head> <script src = "https://cdnjs.cloudflare.com/ajax/libs/underscore.js/1.9.1/underscore-min.js" > </script> </head> <body> <script type="text/javascript"> console.log(_.isRegExp('geek')); </script> </body> </html> 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. html <html> <head> <script src = "https://cdnjs.cloudflare.com/ajax/libs/underscore.js/1.9.1/underscore-min.js" > </script> </head> <body> <script type="text/javascript"> console.log(_.isRegExp('/geek/')); </script> </body> </html> 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. html <html> <head> <script src = "https://cdnjs.cloudflare.com/ajax/libs/underscore.js/1.9.1/underscore-min.js" > </script> </head> <body> <script type="text/javascript"> var a=_.isRegExp(/geek/); var b=_.isRegExp('geek'); var c=a+b; console.log(a, b, c); </script> </body> </html> 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: html <!-- Write HTML code here --> <script type="text/javascript" src = "https://cdnjs.cloudflare.com/ajax/libs/underscore.js/1.9.1/underscore-min.js"> </script> Comment More infoAdvertise with us Next Article Underscore.js _.isRegExp() Function S Sakshi98 Follow Improve Article Tags : Misc JavaScript Web Technologies JavaScript - Underscore.js Practice Tags : Misc 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 _.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 Like